From gclayton at apple.com Mon Jan 30 01:41:32 2012 From: gclayton at apple.com (Greg Clayton) Date: Mon, 30 Jan 2012 07:41:32 -0000 Subject: [Lldb-commits] [lldb] r149231 - in /lldb/trunk: include/lldb/ include/lldb/API/ include/lldb/Core/ include/lldb/Target/ source/API/ source/Core/ source/Target/ Message-ID: <20120130074133.4524F2A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 01:41:31 2012 New Revision: 149231 URL: http://llvm.org/viewvc/llvm-project?rev=149231&view=rev Log: SBFrame is now threadsafe using some extra tricks. One issue is that stack frames might go away (the object itself, not the actual logical frame) when we are single stepping due to the way we currently sometimes end up flushing frames when stepping in/out/over. They later will come back to life represented by another object yet they have the same StackID. Now when you get a lldb::SBFrame object, it will track the frame it is initialized with until the thread goes away or the StackID no longer exists in the stack for the thread it was created on. It uses a weak_ptr to both the frame and thread and also stores the StackID. These three items allow us to determine when the stack frame object has gone away (the weak_ptr will be NULL) and allows us to find the correct frame again. In our test suite we had such cases where we were just getting lucky when something like this happened: 1 - stop at breakpoint 2 - get first frame in thread where we stopped 3 - run an expression that causes the program to JIT and run code 4 - run more expressions on the frame from step 2 which was very very luckily still around inside a shared pointer, yet, not part of the current thread (a new stack frame object had appeared with the same stack ID and depth). We now avoid all such issues and properly keep up to date, or we start returning errors when the frame doesn't exist and always responds with invalid answers. Also fixed the UserSettingsController (not going to rewrite this just yet) so that it doesn't crash on shutdown. Using weak_ptr's came in real handy to track when the master controller has already gone away and this allowed me to pull out the previous NotifyOwnerIsShuttingDown() patch as it is no longer needed. Modified: lldb/trunk/include/lldb/API/SBFrame.h lldb/trunk/include/lldb/API/SBProcess.h lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/include/lldb/Core/Debugger.h lldb/trunk/include/lldb/Core/UserSettingsController.h lldb/trunk/include/lldb/Target/Process.h lldb/trunk/include/lldb/Target/Target.h lldb/trunk/include/lldb/Target/Thread.h lldb/trunk/include/lldb/lldb-forward.h lldb/trunk/source/API/SBAddress.cpp lldb/trunk/source/API/SBCommandInterpreter.cpp lldb/trunk/source/API/SBDebugger.cpp lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/API/SBFunction.cpp lldb/trunk/source/API/SBInstruction.cpp lldb/trunk/source/API/SBModule.cpp lldb/trunk/source/API/SBProcess.cpp lldb/trunk/source/API/SBSourceManager.cpp lldb/trunk/source/API/SBSymbol.cpp lldb/trunk/source/API/SBTarget.cpp lldb/trunk/source/API/SBThread.cpp lldb/trunk/source/API/SBValue.cpp lldb/trunk/source/Core/Debugger.cpp lldb/trunk/source/Core/UserSettingsController.cpp lldb/trunk/source/Target/Process.cpp lldb/trunk/source/Target/Target.cpp lldb/trunk/source/Target/Thread.cpp Modified: lldb/trunk/include/lldb/API/SBFrame.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFrame.h (original) +++ lldb/trunk/include/lldb/API/SBFrame.h Mon Jan 30 01:41:31 2012 @@ -19,6 +19,7 @@ class SBFrame { public: + typedef SHARED_PTR(lldb_private::StackFrameImpl) StackFrameImplSP; SBFrame (); SBFrame (const lldb::SBFrame &rhs); @@ -207,24 +208,13 @@ friend class lldb_private::ScriptInterpreterPython; #endif -#ifndef SWIG - - lldb_private::StackFrame * - operator->() const; - - // Mimic shared pointer... - lldb_private::StackFrame * - get() const; - - lldb::StackFrameSP & - get_sp(); - -#endif + lldb::StackFrameSP + GetFrameSP() const; void - SetFrame (const lldb::StackFrameSP &lldb_object_sp); + SetFrameSP (const lldb::StackFrameSP &lldb_object_sp); - lldb::StackFrameSP m_opaque_sp; + StackFrameImplSP m_opaque_sp; }; } // namespace lldb Modified: lldb/trunk/include/lldb/API/SBProcess.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBProcess.h (original) +++ lldb/trunk/include/lldb/API/SBProcess.h Mon Jan 30 01:41:31 2012 @@ -197,22 +197,13 @@ friend class SBThread; friend class SBValue; -#ifndef SWIG - - lldb_private::Process * - operator->() const; - - // Mimic shared pointer... - lldb_private::Process * - get() const; - -#endif - - SBProcess (const lldb::ProcessSP &process_sp); + lldb::ProcessSP + GetSP() const; + void - SetProcess (const lldb::ProcessSP &process_sp); + SetSP (const lldb::ProcessSP &process_sp); lldb::ProcessSP m_opaque_sp; }; Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Mon Jan 30 01:41:31 2012 @@ -540,17 +540,12 @@ SBTarget (const lldb::TargetSP& target_sp); - void - reset (const lldb::TargetSP& target_sp); - - lldb_private::Target * - operator ->() const; + lldb::TargetSP + GetSP () const; - lldb_private::Target * - get() const; + void + SetSP (const lldb::TargetSP& target_sp); - const lldb::TargetSP & - get_sp () const; private: //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Core/Debugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Debugger.h (original) +++ lldb/trunk/include/lldb/Core/Debugger.h Mon Jan 30 01:41:31 2012 @@ -52,7 +52,7 @@ }; - DebuggerInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); + DebuggerInstanceSettings (const lldb::UserSettingsControllerSP &m_owner_sp, bool live_instance = true, const char *name = NULL); DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs); Modified: lldb/trunk/include/lldb/Core/UserSettingsController.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/UserSettingsController.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/UserSettingsController.h (original) +++ lldb/trunk/include/lldb/Core/UserSettingsController.h Mon Jan 30 01:41:31 2012 @@ -49,7 +49,8 @@ std::vector instance_settings; } UserSettingDefinition; -class UserSettingsController +class UserSettingsController : + public std::tr1::enable_shared_from_this { public: @@ -130,6 +131,11 @@ void RenameInstanceSettings (const char *old_name, const char *new_name); + void + SetDefaultInstanceSettings (const lldb::InstanceSettingsSP &instance_settings_sp) + { + m_default_settings = instance_settings_sp; + } // ------------------------------------------------------------------------- // Public static methods // ------------------------------------------------------------------------- @@ -387,7 +393,7 @@ { public: - InstanceSettings (UserSettingsController &owner, const char *instance_name, bool live_instance = true); + InstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, const char *instance_name, bool live_instance = true); InstanceSettings (const InstanceSettings &rhs); @@ -400,9 +406,6 @@ // Begin Pure Virtual Functions virtual void - NotifyOwnerIsShuttingDown (); - - virtual void UpdateInstanceSettingsVariable (const ConstString &var_name, const char *index_value, const char *value, @@ -442,8 +445,7 @@ protected: - UserSettingsController &m_owner; - bool m_owner_is_live; + lldb::UserSettingsControllerWP m_owner_wp; ConstString m_instance_name; }; Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Mon Jan 30 01:41:31 2012 @@ -54,7 +54,7 @@ { public: - ProcessInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); + ProcessInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL); ProcessInstanceSettings (const ProcessInstanceSettings &rhs); Modified: lldb/trunk/include/lldb/Target/Target.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Target.h (original) +++ lldb/trunk/include/lldb/Target/Target.h Mon Jan 30 01:41:31 2012 @@ -43,7 +43,7 @@ public: static OptionEnumValueElement g_dynamic_value_types[]; - TargetInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); + TargetInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL); TargetInstanceSettings (const TargetInstanceSettings &rhs); Modified: lldb/trunk/include/lldb/Target/Thread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Thread.h (original) +++ lldb/trunk/include/lldb/Target/Thread.h Mon Jan 30 01:41:31 2012 @@ -25,7 +25,7 @@ { public: - ThreadInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); + ThreadInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL); ThreadInstanceSettings (const ThreadInstanceSettings &rhs); Modified: lldb/trunk/include/lldb/lldb-forward.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-forward.h (original) +++ lldb/trunk/include/lldb/lldb-forward.h Mon Jan 30 01:41:31 2012 @@ -142,6 +142,7 @@ class SourceManager; class SourceManagerImpl; class StackFrame; +class StackFrameImpl; class StackFrameList; class StackID; class StopInfo; @@ -293,6 +294,7 @@ typedef std::tr1::shared_ptr TypeImplSP; typedef std::tr1::shared_ptr FuncUnwindersSP; typedef std::tr1::shared_ptr UserSettingsControllerSP; + typedef std::tr1::weak_ptr UserSettingsControllerWP; typedef std::tr1::shared_ptr UnwindPlanSP; typedef lldb_private::SharingPtr ValueObjectSP; typedef std::tr1::shared_ptr ValueSP; Modified: lldb/trunk/source/API/SBAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBAddress.cpp (original) +++ lldb/trunk/source/API/SBAddress.cpp Mon Jan 30 01:41:31 2012 @@ -170,18 +170,19 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); lldb::addr_t addr = LLDB_INVALID_ADDRESS; + TargetSP target_sp (target.GetSP()); if (m_opaque_ap.get()) { - Mutex::Locker api_locker (target->GetAPIMutex()); - addr = m_opaque_ap->GetAddress().GetLoadAddress (target.get()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + addr = m_opaque_ap->GetAddress().GetLoadAddress (target_sp.get()); } if (log) { if (addr == LLDB_INVALID_ADDRESS) - log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target.get()); + log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target_sp.get()); else - log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target.get(), addr); + log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target_sp.get(), addr); } return addr; Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBCommandInterpreter.cpp (original) +++ lldb/trunk/source/API/SBCommandInterpreter.cpp Mon Jan 30 01:41:31 2012 @@ -188,24 +188,26 @@ SBProcess SBCommandInterpreter::GetProcess () { - SBProcess process; + SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_ptr) { TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); if (target_sp) { Mutex::Locker api_locker(target_sp->GetAPIMutex()); - process.SetProcess(target_sp->GetProcessSP()); + process_sp = target_sp->GetProcessSP(); + sb_process.SetSP(process_sp); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)", - m_opaque_ptr, process.get()); + m_opaque_ptr, process_sp.get()); - return process; + return sb_process; } CommandInterpreter * Modified: lldb/trunk/source/API/SBDebugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBDebugger.cpp (original) +++ lldb/trunk/source/API/SBDebugger.cpp Mon Jan 30 01:41:31 2012 @@ -302,11 +302,12 @@ if (m_opaque_sp->GetAsyncExecution() == false) { SBProcess process(GetCommandInterpreter().GetProcess ()); - if (process.IsValid()) + ProcessSP process_sp (process.GetSP()); + if (process_sp) { EventSP event_sp; Listener &lldb_listener = m_opaque_sp->GetListener(); - while (lldb_listener.GetNextEventForBroadcaster (process.get(), event_sp)) + while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp)) { SBEvent event(event_sp); HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle()); @@ -338,11 +339,15 @@ if (!process.IsValid()) return; + TargetSP target_sp (process.GetTarget().GetSP()); + if (!target_sp) + return; + const uint32_t event_type = event.GetType(); char stdio_buffer[1024]; size_t len; - Mutex::Locker api_locker (process.GetTarget()->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) { @@ -474,6 +479,7 @@ lldb::SBError& sb_error) { SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { sb_error.Clear(); @@ -481,7 +487,6 @@ OptionGroupPlatform platform_options (false); platform_options.SetPlatformName (platform_name); - TargetSP target_sp; sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, filename_spec, target_triple, @@ -490,7 +495,7 @@ target_sp); if (sb_error.Success()) - sb_target.reset (target_sp); + sb_target.SetSP (target_sp); } else { @@ -507,7 +512,7 @@ platform_name, add_dependent_modules, sb_error.GetCString(), - sb_target.get()); + target_sp.get()); } return sb_target; @@ -517,7 +522,8 @@ SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, const char *target_triple) { - SBTarget target; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { FileSpec file_spec (filename, true); @@ -529,17 +535,17 @@ add_dependent_modules, NULL, target_sp)); - target.reset (target_sp); + sb_target.SetSP (target_sp); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)", - m_opaque_sp.get(), filename, target_triple, target.get()); + m_opaque_sp.get(), filename, target_triple, target_sp.get()); } - return target; + return sb_target; } SBTarget @@ -547,11 +553,11 @@ { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - SBTarget target; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { FileSpec file (filename, true); - TargetSP target_sp; Error error; const bool add_dependent_modules = true; @@ -565,28 +571,28 @@ if (error.Success()) { m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); - target.reset(target_sp); + sb_target.SetSP (target_sp); } } if (log) { log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)", - m_opaque_sp.get(), filename, arch_cstr, target.get()); + m_opaque_sp.get(), filename, arch_cstr, target_sp.get()); } - return target; + return sb_target; } SBTarget SBDebugger::CreateTarget (const char *filename) { - SBTarget target; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { FileSpec file (filename, true); ArchSpec arch = Target::GetDefaultArchitecture (); - TargetSP target_sp; Error error; const bool add_dependent_modules = true; @@ -600,29 +606,33 @@ if (error.Success()) { m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); - target.reset (target_sp); + sb_target.SetSP (target_sp); } } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", - m_opaque_sp.get(), filename, target.get()); + m_opaque_sp.get(), filename, target_sp.get()); } - return target; + return sb_target; } bool SBDebugger::DeleteTarget (lldb::SBTarget &target) { bool result = false; - if (m_opaque_sp && target.IsValid()) + if (m_opaque_sp) { - // No need to lock, the target list is thread safe - result = m_opaque_sp->GetTargetList().DeleteTarget (target.m_opaque_sp); - target->Destroy(); - target.Clear(); - ModuleList::RemoveOrphanSharedModules(); + TargetSP target_sp(target.GetSP()); + if (target_sp) + { + // No need to lock, the target list is thread safe + result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp); + target_sp->Destroy(); + target.Clear(); + ModuleList::RemoveOrphanSharedModules(); + } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -640,7 +650,7 @@ if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().GetTargetAtIndex (idx)); + sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx)); } return sb_target; } @@ -652,7 +662,7 @@ if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid)); + sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid)); } return sb_target; } @@ -666,7 +676,7 @@ // No need to lock, the target list is thread safe ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get()); TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL)); - sb_target.reset(target_sp); + sb_target.SetSP (target_sp); } return sb_target; } @@ -678,7 +688,7 @@ if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get())); + sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get())); } return sb_target; } @@ -701,10 +711,12 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { // No need to lock, the target list is thread safe - sb_target.reset(m_opaque_sp->GetTargetList().GetSelectedTarget ()); + target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget (); + sb_target.SetSP (target_sp); } if (log) @@ -712,7 +724,7 @@ SBStream sstr; sb_target.GetDescription (sstr, eDescriptionLevelBrief); log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), - sb_target.get(), sstr.GetData()); + target_sp.get(), sstr.GetData()); } return sb_target; @@ -723,16 +735,17 @@ { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + TargetSP target_sp (sb_target.GetSP()); if (m_opaque_sp) { - m_opaque_sp->GetTargetList().SetSelectedTarget (sb_target.get()); + m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get()); } if (log) { SBStream sstr; sb_target.GetDescription (sstr, eDescriptionLevelBrief); log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), - sb_target.get(), sstr.GetData()); + target_sp.get(), sstr.GetData()); } } Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Mon Jan 30 01:41:31 2012 @@ -32,6 +32,7 @@ #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Target/StackFrame.h" +#include "lldb/Target/StackID.h" #include "lldb/Target/Thread.h" #include "lldb/API/SBDebugger.h" @@ -41,16 +42,91 @@ #include "lldb/API/SBSymbolContext.h" #include "lldb/API/SBThread.h" +namespace lldb_private { + + class StackFrameImpl + { + public: + StackFrameImpl (const lldb::StackFrameSP &frame_sp) : + m_frame_wp (frame_sp), + m_thread_wp (), + m_stack_id () + { + if (frame_sp) + { + m_thread_wp = frame_sp->GetThread().shared_from_this(); + m_stack_id = frame_sp->GetStackID(); + } + } + + ~StackFrameImpl() + { + } + + lldb::StackFrameSP + GetFrameSP () + { + lldb::StackFrameSP frame_sp; + // We have a weak pointer to our thread, which might + // be NULL'ed out if the thread went away, so first + // make sure our thread is still alive. + lldb::ThreadSP thread_sp (m_thread_wp.lock()); + if (thread_sp) + { + // Our thread is still here, check if our frame + // is still alive as well. + frame_sp = m_frame_wp.lock(); + if (frame_sp) + { + // Our frame is still alive, make sure that our thread + // still has this exact frame... + lldb::StackFrameSP tmp_frame_sp (thread_sp->GetStackFrameAtIndex (frame_sp->GetFrameIndex())); + if (tmp_frame_sp.get() == frame_sp.get()) + return frame_sp; + } + // The original stack frame might have gone away, + // we need to check for the stac + frame_sp = thread_sp->GetFrameWithStackID (m_stack_id); + m_frame_wp = frame_sp; + } + return frame_sp; + } + + void + SetFrameSP (const lldb::StackFrameSP &frame_sp) + { + if (frame_sp) + { + m_frame_wp = frame_sp; + m_thread_wp = frame_sp->GetThread().shared_from_this(); + m_stack_id = frame_sp->GetStackID(); + } + else + { + m_frame_wp.reset(); + m_thread_wp.reset(); + m_stack_id.Clear(); + } + } + + protected: + lldb::StackFrameWP m_frame_wp; + lldb::ThreadWP m_thread_wp; + StackID m_stack_id; + }; +} // namespace lldb_private + using namespace lldb; using namespace lldb_private; + SBFrame::SBFrame () : m_opaque_sp () { } SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : - m_opaque_sp (lldb_object_sp) + m_opaque_sp (new StackFrameImpl (lldb_object_sp)) { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -59,7 +135,7 @@ SBStream sstr; GetDescription (sstr); log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s", - lldb_object_sp.get(), m_opaque_sp.get(), sstr.GetData()); + lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData()); } } @@ -81,27 +157,45 @@ { } +StackFrameSP +SBFrame::GetFrameSP() const +{ + StackFrameImplSP impl_sp (m_opaque_sp); + StackFrameSP frame_sp; + if (impl_sp) + frame_sp = impl_sp->GetFrameSP(); + return frame_sp; +} void -SBFrame::SetFrame (const StackFrameSP &lldb_object_sp) +SBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp) { - void *old_ptr = m_opaque_sp.get(); - m_opaque_sp = lldb_object_sp; - LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) + if (lldb_object_sp) { - log->Printf ("SBFrame(%p)::SetFrame(sp=%p) := SBFrame(%p)", - old_ptr, lldb_object_sp.get(), m_opaque_sp.get()); + if (m_opaque_sp) + { + StackFrameImplSP impl_sp (m_opaque_sp); + if (impl_sp) + impl_sp->SetFrameSP (lldb_object_sp); + } + else + { + m_opaque_sp = StackFrameImplSP (new StackFrameImpl(lldb_object_sp)); + } + } + else + { + m_opaque_sp.reset(); } - } - bool SBFrame::IsValid() const { - return (m_opaque_sp.get() != NULL); + StackFrameImplSP impl_sp (m_opaque_sp); + if (impl_sp) + return (impl_sp->GetFrameSP().get() != NULL); + return false; } SBSymbolContext @@ -109,16 +203,17 @@ { SBSymbolContext sb_sym_ctx; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_sym_ctx.SetSymbolContext(&m_opaque_sp->GetSymbolContext (resolve_scope)); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_sym_ctx.SetSymbolContext(&frame_sp->GetSymbolContext (resolve_scope)); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", - m_opaque_sp.get(), resolve_scope, sb_sym_ctx.get()); + frame_sp.get(), resolve_scope, sb_sym_ctx.get()); return sb_sym_ctx; } @@ -127,16 +222,17 @@ SBFrame::GetModule () const { SBModule sb_module; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - *sb_module = m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp; + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + *sb_module = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp; } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", - m_opaque_sp.get(), sb_module.get()); + frame_sp.get(), sb_module.get()); return sb_module; } @@ -145,15 +241,16 @@ SBFrame::GetCompileUnit () const { SBCompileUnit sb_comp_unit; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_comp_unit.reset (m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_comp_unit.reset (frame_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)", - m_opaque_sp.get(), sb_comp_unit.get()); + frame_sp.get(), sb_comp_unit.get()); return sb_comp_unit; } @@ -162,15 +259,16 @@ SBFrame::GetFunction () const { SBFunction sb_function; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_function.reset(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_function.reset(frame_sp->GetSymbolContext (eSymbolContextFunction).function); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", - m_opaque_sp.get(), sb_function.get()); + frame_sp.get(), sb_function.get()); return sb_function; } @@ -179,15 +277,16 @@ SBFrame::GetSymbol () const { SBSymbol sb_symbol; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_symbol.reset(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_symbol.reset(frame_sp->GetSymbolContext (eSymbolContextSymbol).symbol); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", - m_opaque_sp.get(), sb_symbol.get()); + frame_sp.get(), sb_symbol.get()); return sb_symbol; } @@ -195,15 +294,16 @@ SBFrame::GetBlock () const { SBBlock sb_block; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.reset (m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_block.reset (frame_sp->GetSymbolContext (eSymbolContextBlock).block); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", - m_opaque_sp.get(), sb_block.get()); + frame_sp.get(), sb_block.get()); return sb_block; } @@ -211,15 +311,16 @@ SBFrame::GetFrameBlock () const { SBBlock sb_block; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.reset(m_opaque_sp->GetFrameBlock ()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_block.reset(frame_sp->GetFrameBlock ()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", - m_opaque_sp.get(), sb_block.get()); + frame_sp.get(), sb_block.get()); return sb_block; } @@ -227,27 +328,33 @@ SBFrame::GetLineEntry () const { SBLineEntry sb_line_entry; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_line_entry.SetLineEntry (m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_line_entry.SetLineEntry (frame_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", - m_opaque_sp.get(), sb_line_entry.get()); + frame_sp.get(), sb_line_entry.get()); return sb_line_entry; } uint32_t SBFrame::GetFrameID () const { - uint32_t frame_idx = m_opaque_sp ? m_opaque_sp->GetFrameIndex () : UINT32_MAX; + uint32_t frame_idx = UINT32_MAX; + + + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) + frame_idx = frame_sp->GetFrameIndex (); LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameID () => %u", - m_opaque_sp.get(), frame_idx); + frame_sp.get(), frame_idx); return frame_idx; } @@ -255,15 +362,16 @@ SBFrame::GetPC () const { addr_t addr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = m_opaque_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&m_opaque_sp->GetThread().GetProcess().GetTarget()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + addr = frame_sp->GetFrameCodeAddress().GetOpcodeLoadAddress (&frame_sp->GetThread().GetProcess().GetTarget()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", m_opaque_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", frame_sp.get(), addr); return addr; } @@ -272,16 +380,17 @@ SBFrame::SetPC (addr_t new_pc) { bool ret_val = false; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - ret_val = m_opaque_sp->GetRegisterContext()->SetPC (new_pc); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + ret_val = frame_sp->GetRegisterContext()->SetPC (new_pc); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i", - m_opaque_sp.get(), new_pc, ret_val); + frame_sp.get(), new_pc, ret_val); return ret_val; } @@ -290,14 +399,15 @@ SBFrame::GetSP () const { addr_t addr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = m_opaque_sp->GetRegisterContext()->GetSP(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + addr = frame_sp->GetRegisterContext()->GetSP(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", m_opaque_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", frame_sp.get(), addr); return addr; } @@ -307,15 +417,16 @@ SBFrame::GetFP () const { addr_t addr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - addr = m_opaque_sp->GetRegisterContext()->GetFP(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + addr = frame_sp->GetRegisterContext()->GetFP(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", m_opaque_sp.get(), addr); + log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", frame_sp.get(), addr); return addr; } @@ -324,14 +435,15 @@ SBFrame::GetPCAddress () const { SBAddress sb_addr; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_addr.SetAddress (&m_opaque_sp->GetFrameCodeAddress()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + sb_addr.SetAddress (&frame_sp->GetFrameCodeAddress()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", m_opaque_sp.get(), sb_addr.get()); + log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame_sp.get(), sb_addr.get()); return sb_addr; } @@ -345,9 +457,10 @@ SBFrame::FindVariable (const char *name) { SBValue value; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); value = FindVariable (name, use_dynamic); } return value; @@ -358,12 +471,12 @@ { VariableSP var_sp; SBValue sb_value; - - if (m_opaque_sp && name && name[0]) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp && name && name[0]) { VariableList variable_list; - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock)); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock)); if (sc.block) { @@ -381,14 +494,14 @@ } if (var_sp) - *sb_value = ValueObjectSP (m_opaque_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic)); + *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic)); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", - m_opaque_sp.get(), name, sb_value.get()); + frame_sp.get(), name, sb_value.get()); return sb_value; } @@ -397,9 +510,10 @@ SBFrame::FindValue (const char *name, ValueType value_type) { SBValue value; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); value = FindValue (name, value_type, use_dynamic); } return value; @@ -409,9 +523,10 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) { SBValue sb_value; - if (m_opaque_sp && name && name[0]) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp && name && name[0]) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); switch (value_type) { @@ -420,9 +535,9 @@ case eValueTypeVariableArgument: // function argument variables case eValueTypeVariableLocal: // function local variables { - VariableList *variable_list = m_opaque_sp->GetVariableList(true); + VariableList *variable_list = frame_sp->GetVariableList(true); - SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock)); + SymbolContext sc (frame_sp->GetSymbolContext (eSymbolContextBlock)); const bool can_create = true; const bool get_parent_variables = true; @@ -442,7 +557,7 @@ variable_sp->GetScope() == value_type && variable_sp->GetName() == const_name) { - *sb_value = ValueObjectSP (m_opaque_sp->GetValueObjectForFrameVariable(variable_sp, + *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(variable_sp, use_dynamic)); break; } @@ -453,7 +568,7 @@ case eValueTypeRegister: // stack frame register value { - RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext()); + RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); if (reg_ctx) { const uint32_t num_regs = reg_ctx->GetRegisterCount(); @@ -464,7 +579,7 @@ ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) { - *sb_value = ValueObjectRegister::Create (m_opaque_sp.get(), reg_ctx, reg_idx); + *sb_value = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx); } } } @@ -473,7 +588,7 @@ case eValueTypeRegisterSet: // A collection of stack frame register values { - RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext()); + RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); if (reg_ctx) { const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); @@ -484,7 +599,7 @@ ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) { - *sb_value = ValueObjectRegisterSet::Create (m_opaque_sp.get(), reg_ctx, set_idx); + *sb_value = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx); } } } @@ -494,7 +609,7 @@ case eValueTypeConstResult: // constant result variables { ConstString const_name(name); - ClangExpressionVariableSP expr_var_sp (m_opaque_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name)); + ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name)); if (expr_var_sp) *sb_value = expr_var_sp->GetValueObject(); } @@ -508,7 +623,7 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", - m_opaque_sp.get(), name, value_type, sb_value.get()); + frame_sp.get(), name, value_type, sb_value.get()); return sb_value; @@ -517,31 +632,13 @@ bool SBFrame::operator == (const SBFrame &rhs) const { - return m_opaque_sp.get() == rhs.m_opaque_sp.get(); + return GetFrameSP().get() == rhs.GetFrameSP().get(); } bool SBFrame::operator != (const SBFrame &rhs) const { - return m_opaque_sp.get() != rhs.m_opaque_sp.get(); -} - -lldb_private::StackFrame * -SBFrame::operator->() const -{ - return m_opaque_sp.get(); -} - -lldb_private::StackFrame * -SBFrame::get() const -{ - return m_opaque_sp.get(); -} - -lldb::StackFrameSP & -SBFrame::get_sp() -{ - return m_opaque_sp; + return GetFrameSP().get() != rhs.GetFrameSP().get(); } SBThread @@ -551,10 +648,11 @@ SBThread sb_thread; ThreadSP thread_sp; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - thread_sp = m_opaque_sp->GetThread().shared_from_this(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + thread_sp = frame_sp->GetThread().shared_from_this(); sb_thread.SetThread (thread_sp); } @@ -562,7 +660,7 @@ { SBStream sstr; sb_thread.GetDescription (sstr); - log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", m_opaque_sp.get(), + log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", frame_sp.get(), thread_sp.get(), sstr.GetData()); } @@ -573,15 +671,16 @@ SBFrame::Disassemble () const { const char *disassembly = NULL; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - disassembly = m_opaque_sp->Disassemble(); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + disassembly = frame_sp->Disassemble(); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBFrame(%p)::Disassemble () => %s", m_opaque_sp.get(), disassembly); + log->Printf ("SBFrame(%p)::Disassemble () => %s", frame_sp.get(), disassembly); return disassembly; } @@ -594,9 +693,10 @@ bool in_scope_only) { SBValueList value_list; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic); } return value_list; @@ -611,24 +711,26 @@ { LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + SBValueList value_list; + StackFrameSP frame_sp(GetFrameSP()); + if (log) log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)", - m_opaque_sp.get(), + frame_sp.get(), arguments, locals, statics, in_scope_only); - - SBValueList value_list; - if (m_opaque_sp) + + if (frame_sp) { size_t i; VariableList *variable_list = NULL; // Scope for locker { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - variable_list = m_opaque_sp->GetVariableList(true); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + variable_list = frame_sp->GetVariableList(true); } if (variable_list) { @@ -661,10 +763,10 @@ } if (add_variable) { - if (in_scope_only && !variable_sp->IsInScope(m_opaque_sp.get())) + if (in_scope_only && !variable_sp->IsInScope(frame_sp.get())) continue; - value_list.Append(m_opaque_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); + value_list.Append(frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); } } } @@ -674,7 +776,7 @@ if (log) { - log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", m_opaque_sp.get(), + log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame_sp.get(), value_list.get()); } @@ -687,22 +789,23 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBValueList value_list; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - RegisterContextSP reg_ctx (m_opaque_sp->GetRegisterContext()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + RegisterContextSP reg_ctx (frame_sp->GetRegisterContext()); if (reg_ctx) { const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) { - value_list.Append(ValueObjectRegisterSet::Create (m_opaque_sp.get(), reg_ctx, set_idx)); + value_list.Append(ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx)); } } } if (log) - log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", m_opaque_sp.get(), value_list.get()); + log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", frame_sp.get(), value_list.get()); return value_list; } @@ -712,10 +815,11 @@ { Stream &strm = description.ref(); - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - m_opaque_sp->DumpUsingSettingsFormat (&strm); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + frame_sp->DumpUsingSettingsFormat (&strm); } else strm.PutCString ("No value"); @@ -727,9 +831,10 @@ SBFrame::EvaluateExpression (const char *expr) { SBValue result; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - lldb::DynamicValueType use_dynamic = m_opaque_sp->CalculateTarget()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); result = EvaluateExpression (expr, use_dynamic); } return result; @@ -744,16 +849,18 @@ ExecutionResults exe_results; SBValue expr_result; + + StackFrameSP frame_sp(GetFrameSP()); if (log) - log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", m_opaque_sp.get(), expr); + log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", frame_sp.get(), expr); - if (m_opaque_sp) + if (frame_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); StreamString frame_description; - m_opaque_sp->DumpUsingSettingsFormat (&frame_description); + frame_sp->DumpUsingSettingsFormat (&frame_description); Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", expr, fetch_dynamic_value, frame_description.GetString().c_str()); @@ -762,14 +869,14 @@ const bool unwind_on_error = true; const bool keep_in_memory = false; - exe_results = m_opaque_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, - m_opaque_sp.get(), - eExecutionPolicyOnlyWhenNeeded, - coerce_to_id, - unwind_on_error, - keep_in_memory, - fetch_dynamic_value, - *expr_result); + exe_results = frame_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, + frame_sp.get(), + eExecutionPolicyOnlyWhenNeeded, + coerce_to_id, + unwind_on_error, + keep_in_memory, + fetch_dynamic_value, + *expr_result); Host::SetCrashDescription (NULL); } @@ -780,7 +887,7 @@ expr_result.GetSummary()); if (log) - log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", m_opaque_sp.get(), + log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(), expr, expr_result.get(), exe_results); @@ -791,9 +898,10 @@ bool SBFrame::IsInlined() { - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - Block *block = m_opaque_sp->GetSymbolContext(eSymbolContextBlock).block; + Block *block = frame_sp->GetSymbolContext(eSymbolContextBlock).block; if (block) return block->GetContainingInlinedBlock () != NULL; } @@ -804,9 +912,10 @@ SBFrame::GetFunctionName() { const char *name = NULL; - if (m_opaque_sp) + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) { - SymbolContext sc (m_opaque_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); + SymbolContext sc (frame_sp->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); if (sc.block) { Block *inlined_block = sc.block->GetContainingInlinedBlock (); Modified: lldb/trunk/source/API/SBFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFunction.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBFunction.cpp (original) +++ lldb/trunk/source/API/SBFunction.cpp Mon Jan 30 01:41:31 2012 @@ -127,11 +127,12 @@ { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } ModuleSP module_sp = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModuleSP(); if (module_sp) Modified: lldb/trunk/source/API/SBInstruction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBInstruction.cpp (original) +++ lldb/trunk/source/API/SBInstruction.cpp Mon Jan 30 01:41:31 2012 @@ -75,11 +75,12 @@ { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } return m_opaque_sp->GetMnemonic(exe_ctx.GetBestExecutionContextScope()); } @@ -93,11 +94,12 @@ { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } return m_opaque_sp->GetOperands(exe_ctx.GetBestExecutionContextScope()); } @@ -111,11 +113,12 @@ { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); - exe_ctx.SetProcessSP(target->GetProcessSP()); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); + exe_ctx.SetProcessSP(target_sp->GetProcessSP()); } return m_opaque_sp->GetComment(exe_ctx.GetBestExecutionContextScope()); } @@ -142,12 +145,13 @@ if (opcode_data && opcode_data_size > 0) { ByteOrder data_byte_order = opcode.GetDataByteOrder(); - if (data_byte_order == eByteOrderInvalid) - data_byte_order = target->GetArchitecture().GetByteOrder(); + TargetSP target_sp (target.GetSP()); + if (data_byte_order == eByteOrderInvalid && target_sp) + data_byte_order = target_sp->GetArchitecture().GetByteOrder(); DataBufferSP data_buffer_sp (new DataBufferHeap (opcode_data, opcode_data_size)); DataExtractorSP data_extractor_sp (new DataExtractor (data_buffer_sp, data_byte_order, - target.IsValid() ? target->GetArchitecture().GetAddressByteSize() : sizeof(void*))); + target_sp ? target_sp->GetArchitecture().GetAddressByteSize() : sizeof(void*))); sb_data.SetOpaque (data_extractor_sp); } } @@ -199,20 +203,25 @@ bool SBInstruction::EmulateWithFrame (lldb::SBFrame &frame, uint32_t evaluate_options) { - if (m_opaque_sp && frame.get()) + if (m_opaque_sp) { - lldb_private::ExecutionContext exe_ctx; - frame->CalculateExecutionContext (exe_ctx); - lldb_private::Target *target = exe_ctx.GetTargetPtr(); - lldb_private::ArchSpec arch = target->GetArchitecture(); - - return m_opaque_sp->Emulate (arch, - evaluate_options, - (void *) frame.get(), - &lldb_private::EmulateInstruction::ReadMemoryFrame, - &lldb_private::EmulateInstruction::WriteMemoryFrame, - &lldb_private::EmulateInstruction::ReadRegisterFrame, - &lldb_private::EmulateInstruction::WriteRegisterFrame); + lldb::StackFrameSP frame_sp (frame.GetFrameSP()); + + if (frame_sp) + { + lldb_private::ExecutionContext exe_ctx; + frame_sp->CalculateExecutionContext (exe_ctx); + lldb_private::Target *target = exe_ctx.GetTargetPtr(); + lldb_private::ArchSpec arch = target->GetArchitecture(); + + return m_opaque_sp->Emulate (arch, + evaluate_options, + (void *) frame_sp.get(), + &lldb_private::EmulateInstruction::ReadMemoryFrame, + &lldb_private::EmulateInstruction::WriteMemoryFrame, + &lldb_private::EmulateInstruction::ReadRegisterFrame, + &lldb_private::EmulateInstruction::WriteRegisterFrame); + } } return false; } Modified: lldb/trunk/source/API/SBModule.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBModule.cpp (original) +++ lldb/trunk/source/API/SBModule.cpp Mon Jan 30 01:41:31 2012 @@ -381,10 +381,8 @@ for (uint32_t i=0; iGetTarget().shared_from_this(); + { + target_sp = m_opaque_sp->GetTarget().shared_from_this(); + sb_target.SetSP (target_sp); + } if (log) - log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), sb_target.get()); + log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), target_sp.get()); return sb_target; } @@ -717,12 +727,6 @@ return broadcaster; } -lldb_private::Process * -SBProcess::operator->() const -{ - return m_opaque_sp.get(); -} - size_t SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error) { @@ -864,13 +868,6 @@ return bytes_written; } -// Mimic shared pointer... -lldb_private::Process * -SBProcess::get() const -{ - return m_opaque_sp.get(); -} - bool SBProcess::GetDescription (SBStream &description) { Modified: lldb/trunk/source/API/SBSourceManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSourceManager.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBSourceManager.cpp (original) +++ lldb/trunk/source/API/SBSourceManager.cpp Mon Jan 30 01:41:31 2012 @@ -89,7 +89,7 @@ SBSourceManager::SBSourceManager (const SBTarget &target) { - m_opaque_ap.reset(new SourceManagerImpl (target.get_sp())); + m_opaque_ap.reset(new SourceManagerImpl (target.GetSP())); } SBSourceManager::SBSourceManager (const SBSourceManager &rhs) Modified: lldb/trunk/source/API/SBSymbol.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbol.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBSymbol.cpp (original) +++ lldb/trunk/source/API/SBSymbol.cpp Mon Jan 30 01:41:31 2012 @@ -123,10 +123,11 @@ { Mutex::Locker api_locker; ExecutionContext exe_ctx; - if (target.IsValid()) + TargetSP target_sp (target.GetSP()); + if (target_sp) { - api_locker.Reset (target->GetAPIMutex().GetMutex()); - target->CalculateExecutionContext (exe_ctx); + api_locker.Reset (target_sp->GetAPIMutex().GetMutex()); + target_sp->CalculateExecutionContext (exe_ctx); } const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr(); if (symbol_range) Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Mon Jan 30 01:41:31 2012 @@ -96,19 +96,19 @@ SBProcess SBTarget::GetProcess () { - SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); + process_sp = m_opaque_sp->GetProcessSP(); + sb_process.SetSP (process_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", - m_opaque_sp.get(), sb_process.get()); + m_opaque_sp.get(), process_sp.get()); } return sb_process; @@ -182,6 +182,7 @@ error.get()); } SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); @@ -190,18 +191,17 @@ launch_flags |= eLaunchFlagDisableASLR; StateType state = eStateInvalid; - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); - if (sb_process.IsValid()) + process_sp = m_opaque_sp->GetProcessSP(); + if (process_sp) { - state = sb_process->GetState(); + state = process_sp->GetState(); - if (sb_process->IsAlive() && state != eStateConnected) + if (process_sp->IsAlive() && state != eStateConnected) { if (state == eStateAttaching) error.SetErrorString ("process attach is in progress"); else error.SetErrorString ("a process is already being debugged"); - sb_process.Clear(); return sb_process; } } @@ -214,20 +214,20 @@ if (listener.IsValid()) { error.SetErrorString ("process is connected and already has a listener, pass empty listener"); - sb_process.Clear(); return sb_process; } } else { if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + process_sp = m_opaque_sp->CreateProcess (listener.ref()); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); } - if (sb_process.IsValid()) + if (process_sp) { + sb_process.SetSP (process_sp); if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) launch_flags |= eLaunchFlagDisableSTDIO; @@ -241,7 +241,7 @@ if (envp) launch_info.GetEnvironmentEntries ().SetArguments (envp); - error.SetError (sb_process->Launch (launch_info)); + error.SetError (process_sp->Launch (launch_info)); if (error.Success()) { // We we are stopping at the entry point, we can return now! @@ -249,17 +249,17 @@ return sb_process; // Make sure we are stopped at the entry - StateType state = sb_process->WaitForProcessToStop (NULL); + StateType state = process_sp->WaitForProcessToStop (NULL); if (state == eStateStopped) { // resume the process to skip the entry point - error.SetError (sb_process->Resume()); + error.SetError (process_sp->Resume()); if (error.Success()) { // If we are doing synchronous mode, then wait for the // process to stop yet again! if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) - sb_process->WaitForProcessToStop (NULL); + process_sp->WaitForProcessToStop (NULL); } } } @@ -278,7 +278,7 @@ if (log) { log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", - m_opaque_sp.get(), sb_process.get()); + m_opaque_sp.get(), process_sp.get()); } return sb_process; @@ -305,23 +305,23 @@ ) { SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); StateType state = eStateInvalid; - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); - if (sb_process.IsValid()) + process_sp = m_opaque_sp->GetProcessSP(); + if (process_sp) { - state = sb_process->GetState(); + state = process_sp->GetState(); - if (sb_process->IsAlive() && state != eStateConnected) + if (process_sp->IsAlive() && state != eStateConnected) { if (state == eStateAttaching) error.SetErrorString ("process attach is in progress"); else error.SetErrorString ("a process is already being debugged"); - sb_process.Clear(); return sb_process; } } @@ -334,27 +334,27 @@ if (listener.IsValid()) { error.SetErrorString ("process is connected and already has a listener, pass empty listener"); - sb_process.Clear(); return sb_process; } } else { if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + process_sp = m_opaque_sp->CreateProcess (listener.ref()); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); } - - if (sb_process.IsValid()) + if (process_sp) { + sb_process.SetSP (process_sp); + ProcessAttachInfo attach_info; attach_info.SetProcessID (pid); - error.SetError (sb_process->Attach (attach_info)); + error.SetError (process_sp->Attach (attach_info)); // If we are doing synchronous mode, then wait for the // process to stop! if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) - sb_process->WaitForProcessToStop (NULL); + process_sp->WaitForProcessToStop (NULL); } else { @@ -379,23 +379,23 @@ ) { SBProcess sb_process; + ProcessSP process_sp; if (name && m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); StateType state = eStateInvalid; - sb_process.SetProcess (m_opaque_sp->GetProcessSP()); - if (sb_process.IsValid()) + process_sp = m_opaque_sp->GetProcessSP(); + if (process_sp) { - state = sb_process->GetState(); + state = process_sp->GetState(); - if (sb_process->IsAlive() && state != eStateConnected) + if (process_sp->IsAlive() && state != eStateConnected) { if (state == eStateAttaching) error.SetErrorString ("process attach is in progress"); else error.SetErrorString ("a process is already being debugged"); - sb_process.Clear(); return sb_process; } } @@ -408,28 +408,28 @@ if (listener.IsValid()) { error.SetErrorString ("process is connected and already has a listener, pass empty listener"); - sb_process.Clear(); return sb_process; } } else { if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref())); + process_sp = m_opaque_sp->CreateProcess (listener.ref()); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); } - if (sb_process.IsValid()) + if (process_sp) { + sb_process.SetSP (process_sp); ProcessAttachInfo attach_info; attach_info.GetExecutableFile().SetFile(name, false); attach_info.SetWaitForLaunch(wait_for); - error.SetError (sb_process->Attach (attach_info)); + error.SetError (process_sp->Attach (attach_info)); // If we are doing synchronous mode, then wait for the // process to stop! if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) - sb_process->WaitForProcessToStop (NULL); + process_sp->WaitForProcessToStop (NULL); } else { @@ -454,18 +454,20 @@ ) { SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); if (listener.IsValid()) - sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref(), plugin_name)); + process_sp = m_opaque_sp->CreateProcess (listener.ref(), plugin_name); else - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name)); + process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name); - if (sb_process.IsValid()) + if (process_sp) { - error.SetError (sb_process->ConnectRemote (url)); + sb_process.SetSP (process_sp); + error.SetError (process_sp->ConnectRemote (url)); } else { @@ -513,26 +515,14 @@ return m_opaque_sp.get() != rhs.m_opaque_sp.get(); } -lldb_private::Target * -SBTarget::operator ->() const -{ - return m_opaque_sp.get(); -} - -lldb_private::Target * -SBTarget::get() const -{ - return m_opaque_sp.get(); -} - -const lldb::TargetSP & -SBTarget::get_sp () const +lldb::TargetSP +SBTarget::GetSP () const { return m_opaque_sp; } void -SBTarget::reset (const lldb::TargetSP& target_sp) +SBTarget::SetSP (const lldb::TargetSP& target_sp) { m_opaque_sp = target_sp; } Modified: lldb/trunk/source/API/SBThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBThread.cpp (original) +++ lldb/trunk/source/API/SBThread.cpp Mon Jan 30 01:41:31 2012 @@ -557,11 +557,12 @@ ThreadSP thread_sp(m_opaque_wp.lock()); + StackFrameSP frame_sp (sb_frame.GetFrameSP()); if (log) { SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); - log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", thread_sp.get(), sb_frame.get(), frame_desc_strm.GetData()); + log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", thread_sp.get(), frame_sp.get(), frame_desc_strm.GetData()); } if (thread_sp) @@ -576,7 +577,7 @@ stop_other_threads, eVoteYes, eVoteNoOpinion, - sb_frame->GetFrameIndex()); + frame_sp->GetFrameIndex()); Process &process = thread_sp->GetProcess(); process.GetThreadList().SetSelectedThreadByID (thread_sp->GetID()); @@ -658,8 +659,9 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); char path[PATH_MAX]; - ThreadSP thread_sp(m_opaque_wp.lock()); - + ThreadSP thread_sp(m_opaque_wp.lock()); + StackFrameSP frame_sp (sb_frame.GetFrameSP()); + if (log) { SBStream frame_desc_strm; @@ -667,7 +669,7 @@ sb_file_spec->GetPath (path, sizeof(path)); log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)", thread_sp.get(), - sb_frame.get(), + frame_sp.get(), frame_desc_strm.GetData(), path, line); } @@ -683,9 +685,7 @@ } StackFrameSP frame_sp; - if (sb_frame.IsValid()) - frame_sp = sb_frame.get_sp(); - else + if (!frame_sp) { frame_sp = thread_sp->GetSelectedFrame (); if (!frame_sp) @@ -843,24 +843,26 @@ SBThread::GetProcess () { - SBProcess process; + SBProcess sb_process; + ProcessSP process_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { // Have to go up to the target so we can get a shared pointer to our process... - process.SetProcess(thread_sp->GetProcess().GetTarget().GetProcessSP()); + process_sp = thread_sp->GetProcess().GetTarget().GetProcessSP(); + sb_process.SetSP (process_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { SBStream frame_desc_strm; - process.GetDescription (frame_desc_strm); + sb_process.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", thread_sp.get(), - process.get(), frame_desc_strm.GetData()); + process_sp.get(), frame_desc_strm.GetData()); } - return process; + return sb_process; } uint32_t @@ -888,11 +890,13 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBFrame sb_frame; + StackFrameSP frame_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex()); - sb_frame.SetFrame (thread_sp->GetStackFrameAtIndex (idx)); + frame_sp = thread_sp->GetStackFrameAtIndex (idx); + sb_frame.SetFrameSP (frame_sp); } if (log) @@ -900,7 +904,7 @@ SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s", - thread_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData()); + thread_sp.get(), idx, frame_sp.get(), frame_desc_strm.GetData()); } return sb_frame; @@ -912,11 +916,13 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBFrame sb_frame; + StackFrameSP frame_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex()); - sb_frame.SetFrame (thread_sp->GetSelectedFrame ()); + frame_sp = thread_sp->GetSelectedFrame (); + sb_frame.SetFrameSP (frame_sp); } if (log) @@ -924,7 +930,7 @@ SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s", - thread_sp.get(), sb_frame.get(), frame_desc_strm.GetData()); + thread_sp.get(), frame_sp.get(), frame_desc_strm.GetData()); } return sb_frame; @@ -936,15 +942,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBFrame sb_frame; + StackFrameSP frame_sp; ThreadSP thread_sp(m_opaque_wp.lock()); if (thread_sp) { Mutex::Locker api_locker (thread_sp->GetProcess().GetTarget().GetAPIMutex()); - lldb::StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (idx)); + frame_sp = thread_sp->GetStackFrameAtIndex (idx); if (frame_sp) { thread_sp->SetSelectedFrame (frame_sp.get()); - sb_frame.SetFrame (frame_sp); + sb_frame.SetFrameSP (frame_sp); } } @@ -953,7 +960,7 @@ SBStream frame_desc_strm; sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s", - thread_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData()); + thread_sp.get(), idx, frame_sp.get(), frame_desc_strm.GetData()); } return sb_frame; } Modified: lldb/trunk/source/API/SBValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/API/SBValue.cpp (original) +++ lldb/trunk/source/API/SBValue.cpp Mon Jan 30 01:41:31 2012 @@ -88,6 +88,8 @@ if (m_opaque_sp.get()) sb_error.SetError(m_opaque_sp->GetError()); + else + sb_error.SetErrorString("error: invalid value"); return sb_error; } @@ -833,46 +835,44 @@ lldb::SBTarget SBValue::GetTarget() { - SBTarget result; + SBTarget sb_target; + TargetSP target_sp; if (m_opaque_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) - { - result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP())); - } + target_sp = m_opaque_sp->GetUpdatePoint().GetTargetSP(); + sb_target.SetSP (target_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.get() == NULL) + if (target_sp.get() == NULL) log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get()); else - log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get()); + log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get()); } - return result; + return sb_target; } lldb::SBProcess SBValue::GetProcess() { - SBProcess result; + SBProcess sb_process; + ProcessSP process_sp; if (m_opaque_sp) { - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) - { - result = SBProcess(lldb::ProcessSP(target->GetProcessSP())); - } + process_sp = m_opaque_sp->GetUpdatePoint().GetProcessSP(); + if (process_sp) + sb_process.SetSP (process_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.get() == NULL) + if (process_sp.get() == NULL) log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get()); else - log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get()); + log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get()); } - return result; + return sb_process; } lldb::SBThread @@ -902,23 +902,25 @@ lldb::SBFrame SBValue::GetFrame() { - SBFrame result; + SBFrame sb_frame; + StackFrameSP frame_sp; if (m_opaque_sp) { if (m_opaque_sp->GetExecutionContextScope()) { - result.SetFrame (m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this()); + frame_sp = m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this(); + sb_frame.SetFrameSP (frame_sp); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.get() == NULL) + if (frame_sp.get() == NULL) log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get()); else - log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get()); + log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get()); } - return result; + return sb_frame; } @@ -1191,17 +1193,25 @@ SBWatchpoint sb_wp_empty; // If the SBValue is not valid, there's no point in even trying to watch it. - if (!IsValid() || !GetFrame().IsValid()) + if (!IsValid()) return sb_wp_empty; // Read and Write cannot both be false. if (!read && !write) return sb_wp_empty; - + // If we are watching the pointee, check that the SBValue is a pointer type. if (watch_pointee && !GetType().IsPointerType()) return sb_wp_empty; + TargetSP target_sp (GetTarget().GetSP()); + if (!target_sp) + return sb_wp_empty; + + StackFrameSP frame_sp (GetFrame().GetFrameSP()); + if (!frame_sp) + return sb_wp_empty; + addr_t addr; size_t size; if (watch_pointee) { @@ -1218,12 +1228,11 @@ uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) | (write ? LLDB_WATCH_TYPE_WRITE : 0); - WatchpointSP wp_sp = GetFrame().m_opaque_sp->GetThread().GetProcess().GetTarget(). - CreateWatchpoint(addr, size, watch_type); + WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, watch_type); if (wp_sp) { // StackFrame::GetInScopeVariableList(true) to get file globals as well. - VariableListSP var_list_sp(GetFrame().m_opaque_sp->GetInScopeVariableList(true)); + VariableListSP var_list_sp(frame_sp->GetInScopeVariableList(true)); VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName())); if (var_sp && var_sp->GetDeclaration().GetFile()) { StreamString ss; Modified: lldb/trunk/source/Core/Debugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/Core/Debugger.cpp (original) +++ lldb/trunk/source/Core/Debugger.cpp Mon Jan 30 01:41:31 2012 @@ -156,8 +156,21 @@ UserSettingsControllerSP & Debugger::GetSettingsController () { - static UserSettingsControllerSP g_settings_controller; - return g_settings_controller; + static UserSettingsControllerSP g_settings_controller_sp; + if (!g_settings_controller_sp) + { + g_settings_controller_sp.reset (new Debugger::SettingsController); + + // The first shared pointer to Debugger::SettingsController in + // g_settings_controller_sp must be fully created above so that + // the DebuggerInstanceSettings can use a weak_ptr to refer back + // to the master setttings controller + InstanceSettingsSP default_instance_settings_sp (new DebuggerInstanceSettings (g_settings_controller_sp, + false, + InstanceSettings::GetDefaultName().AsCString())); + g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp); + } + return g_settings_controller_sp; } int @@ -203,9 +216,7 @@ if (!g_initialized) { g_initialized = true; - UserSettingsControllerSP &usc = GetSettingsController(); - usc.reset (new SettingsController); - UserSettingsController::InitializeSettingsController (usc, + UserSettingsController::InitializeSettingsController (GetSettingsController(), SettingsController::global_settings_table, SettingsController::instance_settings_table); // Now call SettingsInitialize for each settings 'child' of Debugger @@ -317,7 +328,7 @@ Debugger::Debugger () : UserID (g_unique_id++), - DebuggerInstanceSettings (*GetSettingsController()), + DebuggerInstanceSettings (GetSettingsController()), m_input_comm("debugger.input"), m_input_file (), m_output_file (), @@ -2282,8 +2293,6 @@ Debugger::SettingsController::SettingsController () : UserSettingsController ("", UserSettingsControllerSP()) { - m_default_settings.reset (new DebuggerInstanceSettings (*this, false, - InstanceSettings::GetDefaultName().AsCString())); } Debugger::SettingsController::~SettingsController () @@ -2294,9 +2303,9 @@ InstanceSettingsSP Debugger::SettingsController::CreateInstanceSettings (const char *instance_name) { - DebuggerInstanceSettings *new_settings = new DebuggerInstanceSettings (*GetSettingsController(), - false, instance_name); - InstanceSettingsSP new_settings_sp (new_settings); + InstanceSettingsSP new_settings_sp (new DebuggerInstanceSettings (GetSettingsController(), + false, + instance_name)); return new_settings_sp; } @@ -2307,11 +2316,11 @@ DebuggerInstanceSettings::DebuggerInstanceSettings ( - UserSettingsController &owner, + const UserSettingsControllerSP &m_owner_sp, bool live_instance, const char *name ) : - InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), + InstanceSettings (m_owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), m_term_width (80), m_stop_source_before_count (3), m_stop_source_after_count (3), @@ -2332,18 +2341,18 @@ if (GetInstanceName() == InstanceSettings::InvalidName()) { ChangeInstanceName (std::string (CreateInstanceName().AsCString())); - m_owner.RegisterInstanceSettings (this); + m_owner_sp->RegisterInstanceSettings (this); } if (live_instance) { - const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); + const InstanceSettingsSP &pending_settings = m_owner_sp->FindPendingSettings (m_instance_name); CopyInstanceSettings (pending_settings, false); } } DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) : - InstanceSettings (*Debugger::GetSettingsController(), CreateInstanceName ().AsCString()), + InstanceSettings (Debugger::GetSettingsController(), CreateInstanceName ().AsCString()), m_prompt (rhs.m_prompt), m_frame_format (rhs.m_frame_format), m_thread_format (rhs.m_thread_format), @@ -2351,9 +2360,12 @@ m_use_external_editor (rhs.m_use_external_editor), m_auto_confirm_on(rhs.m_auto_confirm_on) { - const InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); - CopyInstanceSettings (pending_settings, false); - m_owner.RemovePendingSettings (m_instance_name); + UserSettingsControllerSP owner_sp (m_owner_wp.lock()); + if (owner_sp) + { + CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false); + owner_sp->RemovePendingSettings (m_instance_name); + } } DebuggerInstanceSettings::~DebuggerInstanceSettings () Modified: lldb/trunk/source/Core/UserSettingsController.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UserSettingsController.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/Core/UserSettingsController.cpp (original) +++ lldb/trunk/source/Core/UserSettingsController.cpp Mon Jan 30 01:41:31 2012 @@ -83,10 +83,6 @@ UserSettingsController::~UserSettingsController () { Mutex::Locker locker (m_live_settings_mutex); - - // Notify all instance settings that their owner is shutting down, first. - for (InstanceSettingsMap::iterator pos = m_live_settings.begin(); pos != m_live_settings.end(); ++pos) - pos->second->NotifyOwnerIsShuttingDown(); m_live_settings.clear(); } @@ -2460,27 +2456,24 @@ // class InstanceSettings //---------------------------------------------------------------------- -InstanceSettings::InstanceSettings (UserSettingsController &owner, const char *instance_name, bool live_instance) : - m_owner (owner), - m_instance_name (instance_name), - m_owner_is_live (true) +InstanceSettings::InstanceSettings (const UserSettingsControllerSP &owner_sp, const char *instance_name, bool live_instance) : + m_owner_wp (owner_sp), + m_instance_name (instance_name) { if ((m_instance_name != InstanceSettings::GetDefaultName()) && (m_instance_name != InstanceSettings::InvalidName()) && live_instance) - m_owner.RegisterInstanceSettings (this); + owner_sp->RegisterInstanceSettings (this); } InstanceSettings::~InstanceSettings () { - if (m_instance_name != InstanceSettings::GetDefaultName() && m_owner_is_live) - m_owner.UnregisterInstanceSettings (this); -} - -void -InstanceSettings::NotifyOwnerIsShuttingDown() -{ - m_owner_is_live = false; + if (m_instance_name != InstanceSettings::GetDefaultName()) + { + UserSettingsControllerSP owner_sp (m_owner_wp.lock()); + if (owner_sp) + owner_sp->UnregisterInstanceSettings (this); + } } const ConstString & Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Mon Jan 30 01:41:31 2012 @@ -741,7 +741,7 @@ Process::Process(Target &target, Listener &listener) : UserID (LLDB_INVALID_PROCESS_ID), Broadcaster ("lldb.process"), - ProcessInstanceSettings (*GetSettingsController()), + ProcessInstanceSettings (GetSettingsController()), m_target (target), m_public_state (eStateUnloaded), m_private_state (eStateUnloaded), @@ -3666,8 +3666,21 @@ UserSettingsControllerSP & Process::GetSettingsController () { - static UserSettingsControllerSP g_settings_controller; - return g_settings_controller; + static UserSettingsControllerSP g_settings_controller_sp; + if (!g_settings_controller_sp) + { + g_settings_controller_sp.reset (new Process::SettingsController); + // The first shared pointer to Process::SettingsController in + // g_settings_controller_sp must be fully created above so that + // the TargetInstanceSettings can use a weak_ptr to refer back + // to the master setttings controller + InstanceSettingsSP default_instance_settings_sp (new ProcessInstanceSettings (g_settings_controller_sp, + false, + InstanceSettings::GetDefaultName().AsCString())); + g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp); + } + return g_settings_controller_sp; + } void @@ -4350,9 +4363,6 @@ Process::SettingsController::SettingsController () : UserSettingsController ("process", Target::GetSettingsController()) { - m_default_settings.reset (new ProcessInstanceSettings (*this, - false, - InstanceSettings::GetDefaultName().AsCString())); } Process::SettingsController::~SettingsController () @@ -4362,10 +4372,9 @@ lldb::InstanceSettingsSP Process::SettingsController::CreateInstanceSettings (const char *instance_name) { - ProcessInstanceSettings *new_settings = new ProcessInstanceSettings (*GetSettingsController(), - false, - instance_name); - lldb::InstanceSettingsSP new_settings_sp (new_settings); + lldb::InstanceSettingsSP new_settings_sp (new ProcessInstanceSettings (GetSettingsController(), + false, + instance_name)); return new_settings_sp; } @@ -4375,11 +4384,11 @@ ProcessInstanceSettings::ProcessInstanceSettings ( - UserSettingsController &owner, + const UserSettingsControllerSP &owner_sp, bool live_instance, const char *name ) : - InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance) + InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance) { // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called // until the vtables for ProcessInstanceSettings are properly set up, i.e. AFTER all the initializers. @@ -4389,25 +4398,27 @@ if (GetInstanceName () == InstanceSettings::InvalidName()) { ChangeInstanceName (std::string (CreateInstanceName().AsCString())); - m_owner.RegisterInstanceSettings (this); + owner_sp->RegisterInstanceSettings (this); } if (live_instance) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); + const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name); CopyInstanceSettings (pending_settings,false); - //m_owner.RemovePendingSettings (m_instance_name); } } ProcessInstanceSettings::ProcessInstanceSettings (const ProcessInstanceSettings &rhs) : - InstanceSettings (*Process::GetSettingsController(), CreateInstanceName().AsCString()) + InstanceSettings (Process::GetSettingsController(), CreateInstanceName().AsCString()) { if (m_instance_name != InstanceSettings::GetDefaultName()) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); - CopyInstanceSettings (pending_settings,false); - m_owner.RemovePendingSettings (m_instance_name); + UserSettingsControllerSP owner_sp (m_owner_wp.lock()); + if (owner_sp) + { + CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false); + owner_sp->RemovePendingSettings (m_instance_name); + } } } Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Mon Jan 30 01:41:31 2012 @@ -47,7 +47,7 @@ Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) : Broadcaster ("lldb.target"), ExecutionContextScope (), - TargetInstanceSettings (*GetSettingsController()), + TargetInstanceSettings (GetSettingsController()), m_debugger (debugger), m_platform_sp (platform_sp), m_mutex (Mutex::eMutexTypeRecursive), @@ -1353,9 +1353,7 @@ void Target::SettingsInitialize () { - UserSettingsControllerSP &usc = GetSettingsController(); - usc.reset (new SettingsController); - UserSettingsController::InitializeSettingsController (usc, + UserSettingsController::InitializeSettingsController (GetSettingsController(), SettingsController::global_settings_table, SettingsController::instance_settings_table); @@ -1381,8 +1379,20 @@ UserSettingsControllerSP & Target::GetSettingsController () { - static UserSettingsControllerSP g_settings_controller; - return g_settings_controller; + static UserSettingsControllerSP g_settings_controller_sp; + if (!g_settings_controller_sp) + { + g_settings_controller_sp.reset (new Target::SettingsController); + // The first shared pointer to Target::SettingsController in + // g_settings_controller_sp must be fully created above so that + // the TargetInstanceSettings can use a weak_ptr to refer back + // to the master setttings controller + InstanceSettingsSP default_instance_settings_sp (new TargetInstanceSettings (g_settings_controller_sp, + false, + InstanceSettings::GetDefaultName().AsCString())); + g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp); + } + return g_settings_controller_sp; } ArchSpec @@ -1985,8 +1995,6 @@ UserSettingsController ("target", Debugger::GetSettingsController()), m_default_architecture () { - m_default_settings.reset (new TargetInstanceSettings (*this, false, - InstanceSettings::GetDefaultName().AsCString())); } Target::SettingsController::~SettingsController () @@ -1996,10 +2004,9 @@ lldb::InstanceSettingsSP Target::SettingsController::CreateInstanceSettings (const char *instance_name) { - TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(), - false, - instance_name); - lldb::InstanceSettingsSP new_settings_sp (new_settings); + lldb::InstanceSettingsSP new_settings_sp (new TargetInstanceSettings (GetSettingsController(), + false, + instance_name)); return new_settings_sp; } @@ -2176,11 +2183,11 @@ TargetInstanceSettings::TargetInstanceSettings ( - UserSettingsController &owner, + const lldb::UserSettingsControllerSP &owner_sp, bool live_instance, const char *name ) : - InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), + InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), m_expr_prefix_file (), m_expr_prefix_contents (), m_prefer_dynamic_value (2), @@ -2207,18 +2214,18 @@ if (GetInstanceName () == InstanceSettings::InvalidName()) { ChangeInstanceName (std::string (CreateInstanceName().AsCString())); - m_owner.RegisterInstanceSettings (this); + owner_sp->RegisterInstanceSettings (this); } if (live_instance) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); + const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name); CopyInstanceSettings (pending_settings,false); } } TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) : - InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()), + InstanceSettings (Target::GetSettingsController(), CreateInstanceName().AsCString()), m_expr_prefix_file (rhs.m_expr_prefix_file), m_expr_prefix_contents (rhs.m_expr_prefix_contents), m_prefer_dynamic_value (rhs.m_prefer_dynamic_value), @@ -2238,8 +2245,9 @@ { if (m_instance_name != InstanceSettings::GetDefaultName()) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); - CopyInstanceSettings (pending_settings,false); + UserSettingsControllerSP owner_sp (m_owner_wp.lock()); + if (owner_sp) + CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false); } } Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=149231&r1=149230&r2=149231&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Mon Jan 30 01:41:31 2012 @@ -45,7 +45,7 @@ Thread::Thread (Process &process, lldb::tid_t tid) : UserID (tid), - ThreadInstanceSettings (*GetSettingsController()), + ThreadInstanceSettings (GetSettingsController()), m_process (process), m_actual_stop_info_sp (), m_index_id (process.GetNextThreadIndexID ()), @@ -1033,9 +1033,7 @@ void Thread::SettingsInitialize () { - UserSettingsControllerSP &usc = GetSettingsController(); - usc.reset (new SettingsController); - UserSettingsController::InitializeSettingsController (usc, + UserSettingsController::InitializeSettingsController (GetSettingsController(), SettingsController::global_settings_table, SettingsController::instance_settings_table); @@ -1059,8 +1057,21 @@ UserSettingsControllerSP & Thread::GetSettingsController () { - static UserSettingsControllerSP g_settings_controller; - return g_settings_controller; + static UserSettingsControllerSP g_settings_controller_sp; + if (!g_settings_controller_sp) + { + g_settings_controller_sp.reset (new Thread::SettingsController); + // The first shared pointer to Target::SettingsController in + // g_settings_controller_sp must be fully created above so that + // the TargetInstanceSettings can use a weak_ptr to refer back + // to the master setttings controller + InstanceSettingsSP default_instance_settings_sp (new ThreadInstanceSettings (g_settings_controller_sp, + false, + InstanceSettings::GetDefaultName().AsCString())); + + g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp); + } + return g_settings_controller_sp; } void @@ -1243,8 +1254,6 @@ Thread::SettingsController::SettingsController () : UserSettingsController ("thread", Process::GetSettingsController()) { - m_default_settings.reset (new ThreadInstanceSettings (*this, false, - InstanceSettings::GetDefaultName().AsCString())); } Thread::SettingsController::~SettingsController () @@ -1254,10 +1263,9 @@ lldb::InstanceSettingsSP Thread::SettingsController::CreateInstanceSettings (const char *instance_name) { - ThreadInstanceSettings *new_settings = new ThreadInstanceSettings (*GetSettingsController(), - false, - instance_name); - lldb::InstanceSettingsSP new_settings_sp (new_settings); + lldb::InstanceSettingsSP new_settings_sp (new ThreadInstanceSettings (GetSettingsController(), + false, + instance_name)); return new_settings_sp; } @@ -1266,8 +1274,8 @@ // class ThreadInstanceSettings //-------------------------------------------------------------- -ThreadInstanceSettings::ThreadInstanceSettings (UserSettingsController &owner, bool live_instance, const char *name) : - InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), +ThreadInstanceSettings::ThreadInstanceSettings (const UserSettingsControllerSP &owner_sp, bool live_instance, const char *name) : + InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), m_avoid_regexp_ap (), m_trace_enabled (false) { @@ -1279,27 +1287,28 @@ if (GetInstanceName() == InstanceSettings::InvalidName()) { ChangeInstanceName (std::string (CreateInstanceName().AsCString())); - m_owner.RegisterInstanceSettings (this); + owner_sp->RegisterInstanceSettings (this); } if (live_instance) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); - CopyInstanceSettings (pending_settings,false); - //m_owner.RemovePendingSettings (m_instance_name); + CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false); } } ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) : - InstanceSettings (*Thread::GetSettingsController(), CreateInstanceName().AsCString()), + InstanceSettings (Thread::GetSettingsController(), CreateInstanceName().AsCString()), m_avoid_regexp_ap (), m_trace_enabled (rhs.m_trace_enabled) { if (m_instance_name != InstanceSettings::GetDefaultName()) { - const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); - CopyInstanceSettings (pending_settings,false); - m_owner.RemovePendingSettings (m_instance_name); + UserSettingsControllerSP owner_sp (m_owner_wp.lock()); + if (owner_sp) + { + CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false); + owner_sp->RemovePendingSettings (m_instance_name); + } } if (rhs.m_avoid_regexp_ap.get() != NULL) m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText())); From gclayton at apple.com Mon Jan 30 03:04:36 2012 From: gclayton at apple.com (Greg Clayton) Date: Mon, 30 Jan 2012 09:04:36 -0000 Subject: [Lldb-commits] [lldb] r149238 - in /lldb/trunk: include/lldb/API/SBModule.h source/API/SBAddress.cpp source/API/SBFrame.cpp source/API/SBModule.cpp source/API/SBProcess.cpp source/API/SBSymbolContext.cpp source/API/SBTarget.cpp Message-ID: <20120130090436.DBD402A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 03:04:36 2012 New Revision: 149238 URL: http://llvm.org/viewvc/llvm-project?rev=149238&view=rev Log: lldb::SBTarget and lldb::SBProcess are now thread hardened. They both still contain shared pointers to the lldb_private::Target and lldb_private::Process objects respectively as we won't want the target or process just going away. Also cleaned up the lldb::SBModule to remove dangerous pointer accessors. For any code the public API files, we should always be grabbing shared pointers to any objects for the current class, and any other classes prior to running code with them. Modified: lldb/trunk/include/lldb/API/SBModule.h lldb/trunk/source/API/SBAddress.cpp lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/API/SBModule.cpp lldb/trunk/source/API/SBProcess.cpp lldb/trunk/source/API/SBSymbolContext.cpp lldb/trunk/source/API/SBTarget.cpp Modified: lldb/trunk/include/lldb/API/SBModule.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBModule.h?rev=149238&r1=149237&r2=149238&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBModule.h (original) +++ lldb/trunk/include/lldb/API/SBModule.h Mon Jan 30 03:04:36 2012 @@ -188,31 +188,11 @@ explicit SBModule (const lldb::ModuleSP& module_sp); - void - SetModule (const lldb::ModuleSP& module_sp); -#ifndef SWIG - - lldb::ModuleSP & - operator *(); - - - lldb_private::Module * - operator ->(); - - const lldb_private::Module * - operator ->() const; - - lldb_private::Module * - get(); - - const lldb_private::Module * - get() const; - - const lldb::ModuleSP & - get_sp() const; + ModuleSP + GetSP () const; - -#endif + void + SetSP (const ModuleSP &module_sp); lldb::ModuleSP m_opaque_sp; }; Modified: lldb/trunk/source/API/SBAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=149238&r1=149237&r2=149238&view=diff ============================================================================== --- lldb/trunk/source/API/SBAddress.cpp (original) +++ lldb/trunk/source/API/SBAddress.cpp Mon Jan 30 03:04:36 2012 @@ -300,9 +300,7 @@ SBModule sb_module; if (m_opaque_ap.get()) { - Module *module = m_opaque_ap->GetModule(); - if (module) - *sb_module = module->shared_from_this(); + sb_module.SetSP (m_opaque_ap->GetModuleSP()); } return sb_module; } Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=149238&r1=149237&r2=149238&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Mon Jan 30 03:04:36 2012 @@ -222,17 +222,19 @@ SBFrame::GetModule () const { SBModule sb_module; + ModuleSP module_sp; StackFrameSP frame_sp(GetFrameSP()); if (frame_sp) { Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - *sb_module = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp; + module_sp = frame_sp->GetSymbolContext (eSymbolContextModule).module_sp; + sb_module.SetSP (module_sp); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", - frame_sp.get(), sb_module.get()); + frame_sp.get(), module_sp.get()); return sb_module; } Modified: lldb/trunk/source/API/SBModule.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=149238&r1=149237&r2=149238&view=diff ============================================================================== --- lldb/trunk/source/API/SBModule.cpp (original) +++ lldb/trunk/source/API/SBModule.cpp Mon Jan 30 03:04:36 2012 @@ -193,49 +193,18 @@ return false; } -lldb::ModuleSP & -SBModule::operator *() -{ - return m_opaque_sp; -} - -lldb_private::Module * -SBModule::operator ->() -{ - return m_opaque_sp.get(); -} - -const lldb_private::Module * -SBModule::operator ->() const -{ - return m_opaque_sp.get(); -} - -lldb_private::Module * -SBModule::get() -{ - return m_opaque_sp.get(); -} - -const lldb_private::Module * -SBModule::get() const -{ - return m_opaque_sp.get(); -} - -const lldb::ModuleSP & -SBModule::get_sp() const +ModuleSP +SBModule::GetSP () const { return m_opaque_sp; } void -SBModule::SetModule (const lldb::ModuleSP& module_sp) +SBModule::SetSP (const ModuleSP &module_sp) { m_opaque_sp = module_sp; } - SBAddress SBModule::ResolveFileAddress (lldb::addr_t vm_addr) { Modified: lldb/trunk/source/API/SBProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=149238&r1=149237&r2=149238&view=diff ============================================================================== --- lldb/trunk/source/API/SBProcess.cpp (original) +++ lldb/trunk/source/API/SBProcess.cpp Mon Jan 30 03:04:36 2012 @@ -125,10 +125,11 @@ error.get()); } - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - if (m_opaque_sp->GetState() == eStateConnected) + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + if (process_sp->GetState() == eStateConnected) { if (stop_at_entry) launch_flags |= eLaunchFlagStopAtEntry; @@ -137,14 +138,14 @@ stderr_path, working_directory, launch_flags); - Module *exe_module = m_opaque_sp->GetTarget().GetExecutableModulePointer(); + Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); if (exe_module) launch_info.SetExecutableFile(exe_module->GetFileSpec(), true); if (argv) launch_info.GetArguments().AppendArguments (argv); if (envp) launch_info.GetEnvironmentEntries ().SetArguments (envp); - error.SetError (m_opaque_sp->Launch (launch_info)); + error.SetError (process_sp->Launch (launch_info)); } else { @@ -159,7 +160,7 @@ if (log) { SBStream sstr; error.GetDescription (sstr); - log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", m_opaque_sp.get(), error.get(), sstr.GetData()); + log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", process_sp.get(), error.get(), sstr.GetData()); } return error.Success(); @@ -168,14 +169,15 @@ bool SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error) { - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - if (m_opaque_sp->GetState() == eStateConnected) + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + if (process_sp->GetState() == eStateConnected) { ProcessAttachInfo attach_info; attach_info.SetProcessID (pid); - error.SetError (m_opaque_sp->Attach (attach_info)); + error.SetError (process_sp->Attach (attach_info)); } else { @@ -191,7 +193,7 @@ if (log) { SBStream sstr; error.GetDescription (sstr); - log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%llu) => SBError (%p): %s", m_opaque_sp.get(), pid, error.get(), sstr.GetData()); + log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%llu) => SBError (%p): %s", process_sp.get(), pid, error.get(), sstr.GetData()); } return error.Success(); @@ -204,15 +206,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); uint32_t num_threads = 0; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); const bool can_update = true; - num_threads = m_opaque_sp->GetThreadList().GetSize(can_update); + num_threads = process_sp->GetThreadList().GetSize(can_update); } if (log) - log->Printf ("SBProcess(%p)::GetNumThreads () => %d", m_opaque_sp.get(), num_threads); + log->Printf ("SBProcess(%p)::GetNumThreads () => %d", process_sp.get(), num_threads); return num_threads; } @@ -224,16 +227,17 @@ SBThread sb_thread; ThreadSP thread_sp; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - thread_sp = m_opaque_sp->GetThreadList().GetSelectedThread(); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + thread_sp = process_sp->GetThreadList().GetSelectedThread(); sb_thread.SetThread (thread_sp); } if (log) { - log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", m_opaque_sp.get(), thread_sp.get()); + log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", process_sp.get(), thread_sp.get()); } return sb_thread; @@ -246,14 +250,15 @@ SBTarget sb_target; TargetSP target_sp; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - target_sp = m_opaque_sp->GetTarget().shared_from_this(); + target_sp = process_sp->GetTarget().shared_from_this(); sb_target.SetSP (target_sp); } if (log) - log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", m_opaque_sp.get(), target_sp.get()); + log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", process_sp.get(), target_sp.get()); return sb_target; } @@ -265,15 +270,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); size_t ret_val = 0; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { Error error; - ret_val = m_opaque_sp->PutSTDIN (src, src_len, error); + ret_val = process_sp->PutSTDIN (src, src_len, error); } if (log) log->Printf ("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%d) => %lu", - m_opaque_sp.get(), + process_sp.get(), src, (uint32_t) src_len, ret_val); @@ -285,16 +291,17 @@ SBProcess::GetSTDOUT (char *dst, size_t dst_len) const { size_t bytes_read = 0; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { Error error; - bytes_read = m_opaque_sp->GetSTDOUT (dst, dst_len, error); + bytes_read = process_sp->GetSTDOUT (dst, dst_len, error); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%zu) => %zu", - m_opaque_sp.get(), (int) bytes_read, dst, dst_len, bytes_read); + process_sp.get(), (int) bytes_read, dst, dst_len, bytes_read); return bytes_read; } @@ -303,16 +310,17 @@ SBProcess::GetSTDERR (char *dst, size_t dst_len) const { size_t bytes_read = 0; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { Error error; - bytes_read = m_opaque_sp->GetSTDERR (dst, dst_len, error); + bytes_read = process_sp->GetSTDERR (dst, dst_len, error); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%zu) => %zu", - m_opaque_sp.get(), (int) bytes_read, dst, dst_len, bytes_read); + process_sp.get(), (int) bytes_read, dst, dst_len, bytes_read); return bytes_read; } @@ -323,14 +331,15 @@ if (out == NULL) return; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { const StateType event_state = SBProcess::GetStateFromEvent (event); char message[1024]; int message_len = ::snprintf (message, sizeof (message), "Process %llu %s\n", - m_opaque_sp->GetID(), + process_sp->GetID(), SBDebugger::StateAsCString (event_state)); if (message_len > 0) @@ -341,14 +350,15 @@ void SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result) { - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { const StateType event_state = SBProcess::GetStateFromEvent (event); char message[1024]; ::snprintf (message, sizeof (message), "Process %llu %s\n", - m_opaque_sp->GetID(), + process_sp->GetID(), SBDebugger::StateAsCString (event_state)); result.AppendMessage (message); @@ -358,10 +368,11 @@ bool SBProcess::SetSelectedThread (const SBThread &thread) { - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); } return false; } @@ -372,15 +383,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); bool ret_val = false; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - ret_val = m_opaque_sp->GetThreadList().SetSelectedThreadByID (tid); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid); } if (log) log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4x) => %s", - m_opaque_sp.get(), tid, (ret_val ? "true" : "false")); + process_sp.get(), tid, (ret_val ? "true" : "false")); return ret_val; } @@ -392,17 +404,18 @@ SBThread sb_thread; ThreadSP thread_sp; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - thread_sp = m_opaque_sp->GetThreadList().GetThreadAtIndex(index); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index); sb_thread.SetThread (thread_sp); } if (log) { log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)", - m_opaque_sp.get(), (uint32_t) index, thread_sp.get()); + process_sp.get(), (uint32_t) index, thread_sp.get()); } return sb_thread; @@ -413,16 +426,17 @@ { StateType ret_val = eStateInvalid; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - ret_val = m_opaque_sp->GetState(); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + ret_val = process_sp->GetState(); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::GetState () => %s", - m_opaque_sp.get(), + process_sp.get(), lldb_private::StateAsCString (ret_val)); return ret_val; @@ -433,15 +447,16 @@ SBProcess::GetExitStatus () { int exit_status = 0; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - exit_status = m_opaque_sp->GetExitStatus (); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + exit_status = process_sp->GetExitStatus (); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)", - m_opaque_sp.get(), exit_status, exit_status); + process_sp.get(), exit_status, exit_status); return exit_status; } @@ -450,15 +465,16 @@ SBProcess::GetExitDescription () { const char *exit_desc = NULL; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - exit_desc = m_opaque_sp->GetExitDescription (); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + exit_desc = process_sp->GetExitDescription (); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::GetExitDescription () => %s", - m_opaque_sp.get(), exit_desc); + process_sp.get(), exit_desc); return exit_desc; } @@ -466,12 +482,13 @@ SBProcess::GetProcessID () { lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID; - if (m_opaque_sp) - ret_val = m_opaque_sp->GetID(); + ProcessSP process_sp(GetSP()); + if (process_sp) + ret_val = process_sp->GetID(); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBProcess(%p)::GetProcessID () => %llu", m_opaque_sp.get(), ret_val); + log->Printf ("SBProcess(%p)::GetProcessID () => %llu", process_sp.get(), ret_val); return ret_val; } @@ -480,12 +497,13 @@ SBProcess::GetByteOrder () const { ByteOrder byteOrder = eByteOrderInvalid; - if (m_opaque_sp) - byteOrder = m_opaque_sp->GetTarget().GetArchitecture().GetByteOrder(); + ProcessSP process_sp(GetSP()); + if (process_sp) + byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder(); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBProcess(%p)::GetByteOrder () => %d", m_opaque_sp.get(), byteOrder); + log->Printf ("SBProcess(%p)::GetByteOrder () => %d", process_sp.get(), byteOrder); return byteOrder; } @@ -494,12 +512,13 @@ SBProcess::GetAddressByteSize () const { uint32_t size = 0; - if (m_opaque_sp) - size = m_opaque_sp->GetTarget().GetArchitecture().GetAddressByteSize(); + ProcessSP process_sp(GetSP()); + if (process_sp) + size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize(); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", m_opaque_sp.get(), size); + log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", process_sp.get(), size); return size; } @@ -508,22 +527,25 @@ SBProcess::Continue () { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBProcess(%p)::Continue ()...", m_opaque_sp.get()); SBError sb_error; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + + if (log) + log->Printf ("SBProcess(%p)::Continue ()...", process_sp.get()); + + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); - Error error (m_opaque_sp->Resume()); + Error error (process_sp->Resume()); if (error.Success()) { - if (m_opaque_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) + if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) { if (log) - log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", m_opaque_sp.get()); - m_opaque_sp->WaitForProcessToStop (NULL); + log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", process_sp.get()); + process_sp->WaitForProcessToStop (NULL); } } sb_error.SetError(error); @@ -535,7 +557,7 @@ { SBStream sstr; sb_error.GetDescription (sstr); - log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", m_opaque_sp.get(), sb_error.get(), sstr.GetData()); + log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", process_sp.get(), sb_error.get(), sstr.GetData()); } return sb_error; @@ -546,10 +568,11 @@ SBProcess::Destroy () { SBError sb_error; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - sb_error.SetError(m_opaque_sp->Destroy()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + sb_error.SetError(process_sp->Destroy()); } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -560,7 +583,7 @@ SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", - m_opaque_sp.get(), + process_sp.get(), sb_error.get(), sstr.GetData()); } @@ -573,10 +596,11 @@ SBProcess::Stop () { SBError sb_error; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - sb_error.SetError (m_opaque_sp->Halt()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + sb_error.SetError (process_sp->Halt()); } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -587,7 +611,7 @@ SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s", - m_opaque_sp.get(), + process_sp.get(), sb_error.get(), sstr.GetData()); } @@ -599,10 +623,11 @@ SBProcess::Kill () { SBError sb_error; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - sb_error.SetError (m_opaque_sp->Destroy()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + sb_error.SetError (process_sp->Destroy()); } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -613,7 +638,7 @@ SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s", - m_opaque_sp.get(), + process_sp.get(), sb_error.get(), sstr.GetData()); } @@ -625,10 +650,11 @@ SBProcess::Detach () { SBError sb_error; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - sb_error.SetError (m_opaque_sp->Detach()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + sb_error.SetError (process_sp->Detach()); } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -640,10 +666,11 @@ SBProcess::Signal (int signo) { SBError sb_error; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - sb_error.SetError (m_opaque_sp->Signal (signo)); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + sb_error.SetError (process_sp->Signal (signo)); } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -653,7 +680,7 @@ SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s", - m_opaque_sp.get(), + process_sp.get(), signo, sb_error.get(), sstr.GetData()); @@ -666,10 +693,11 @@ { SBThread sb_thread; ThreadSP thread_sp; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - thread_sp = m_opaque_sp->GetThreadList().FindThreadByID (tid); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + thread_sp = process_sp->GetThreadList().FindThreadByID (tid); sb_thread.SetThread (thread_sp); } @@ -677,7 +705,7 @@ if (log) { log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4llx) => SBThread (%p)", - m_opaque_sp.get(), + process_sp.get(), tid, thread_sp.get()); } @@ -718,10 +746,12 @@ { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - SBBroadcaster broadcaster(m_opaque_sp.get(), false); + ProcessSP process_sp(GetSP()); + + SBBroadcaster broadcaster(process_sp.get(), false); if (log) - log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", m_opaque_sp.get(), + log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", process_sp.get(), broadcaster.get()); return broadcaster; @@ -734,21 +764,23 @@ size_t bytes_read = 0; + ProcessSP process_sp(GetSP()); + if (log) { log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p))...", - m_opaque_sp.get(), + process_sp.get(), addr, dst, dst_len, sb_error.get()); } - - if (m_opaque_sp) + + if (process_sp) { Error error; - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - bytes_read = m_opaque_sp->ReadMemory (addr, dst, dst_len, error); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + bytes_read = process_sp->ReadMemory (addr, dst, dst_len, error); sb_error.SetError (error); } else @@ -761,7 +793,7 @@ SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%llx, dst=%p, dst_len=%zu, SBError (%p): %s) => %zu", - m_opaque_sp.get(), + process_sp.get(), addr, dst, dst_len, @@ -777,11 +809,12 @@ SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error) { size_t bytes_read = 0; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { Error error; - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - bytes_read = m_opaque_sp->ReadCStringFromMemory (addr, (char *)buf, size, error); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, error); sb_error.SetError (error); } else @@ -794,11 +827,12 @@ uint64_t SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error) { - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { Error error; - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - uint64_t value = m_opaque_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, error); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + uint64_t value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, error); sb_error.SetError (error); return value; } @@ -813,11 +847,12 @@ SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error) { lldb::addr_t ptr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { Error error; - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - ptr = m_opaque_sp->ReadPointerFromMemory (addr, error); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + ptr = process_sp->ReadPointerFromMemory (addr, error); sb_error.SetError (error); } else @@ -833,21 +868,24 @@ size_t bytes_written = 0; LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + ProcessSP process_sp(GetSP()); + if (log) { log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p))...", - m_opaque_sp.get(), + process_sp.get(), addr, src, src_len, sb_error.get()); } - if (m_opaque_sp) + if (process_sp) { Error error; - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - bytes_written = m_opaque_sp->WriteMemory (addr, src, src_len, error); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + bytes_written = process_sp->WriteMemory (addr, src, src_len, error); sb_error.SetError (error); } @@ -856,7 +894,7 @@ SBStream sstr; sb_error.GetDescription (sstr); log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%llx, src=%p, dst_len=%zu, SBError (%p): %s) => %zu", - m_opaque_sp.get(), + process_sp.get(), addr, src, src_len, @@ -873,17 +911,18 @@ { Stream &strm = description.ref(); - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { char path[PATH_MAX]; GetTarget().GetExecutable().GetPath (path, sizeof(path)); - Module *exe_module = m_opaque_sp->GetTarget().GetExecutableModulePointer(); + Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer(); const char *exe_name = NULL; if (exe_module) exe_name = exe_module->GetFileSpec().GetFilename().AsCString(); strm.Printf ("SBProcess: pid = %llu, state = %s, threads = %d%s%s", - m_opaque_sp->GetID(), + process_sp->GetID(), lldb_private::StateAsCString (GetState()), GetNumThreads(), exe_name ? ", executable = " : "", @@ -898,10 +937,11 @@ uint32_t SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) { - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->LoadImage (*sb_image_spec, sb_error.ref()); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + return process_sp->LoadImage (*sb_image_spec, sb_error.ref()); } return LLDB_INVALID_IMAGE_TOKEN; } @@ -910,10 +950,11 @@ SBProcess::UnloadImage (uint32_t image_token) { lldb::SBError sb_error; - if (m_opaque_sp) + ProcessSP process_sp(GetSP()); + if (process_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - sb_error.SetError (m_opaque_sp->UnloadImage (image_token)); + Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); + sb_error.SetError (process_sp->UnloadImage (image_token)); } else sb_error.SetErrorString("invalid process"); Modified: lldb/trunk/source/API/SBSymbolContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbolContext.cpp?rev=149238&r1=149237&r2=149238&view=diff ============================================================================== --- lldb/trunk/source/API/SBSymbolContext.cpp (original) +++ lldb/trunk/source/API/SBSymbolContext.cpp Mon Jan 30 03:04:36 2012 @@ -90,15 +90,19 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBModule sb_module; + ModuleSP module_sp; if (m_opaque_ap.get()) - sb_module.SetModule(m_opaque_ap->module_sp); + { + module_sp = m_opaque_ap->module_sp; + sb_module.SetSP (module_sp); + } if (log) { SBStream sstr; sb_module.GetDescription (sstr); log->Printf ("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s", - m_opaque_ap.get(), sb_module.get(), sstr.GetData()); + m_opaque_ap.get(), module_sp.get(), sstr.GetData()); } return sb_module; @@ -177,7 +181,7 @@ void SBSymbolContext::SetModule (lldb::SBModule module) { - ref().module_sp = module.get_sp(); + ref().module_sp = module.GetSP(); } void Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=149238&r1=149237&r2=149238&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Mon Jan 30 03:04:36 2012 @@ -98,9 +98,10 @@ { SBProcess sb_process; ProcessSP process_sp; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - process_sp = m_opaque_sp->GetProcessSP(); + process_sp = target_sp->GetProcessSP(); sb_process.SetSP (process_sp); } @@ -108,7 +109,7 @@ if (log) { log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", - m_opaque_sp.get(), process_sp.get()); + target_sp.get(), process_sp.get()); } return sb_process; @@ -118,8 +119,9 @@ SBTarget::GetDebugger () const { SBDebugger debugger; - if (m_opaque_sp) - debugger.reset (m_opaque_sp->GetDebugger().shared_from_this()); + TargetSP target_sp(GetSP()); + if (target_sp) + debugger.reset (target_sp->GetDebugger().shared_from_this()); return debugger; } @@ -167,10 +169,14 @@ { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + SBProcess sb_process; + ProcessSP process_sp; + TargetSP target_sp(GetSP()); + if (log) { log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", - m_opaque_sp.get(), + target_sp.get(), argv, envp, stdin_path ? stdin_path : "NULL", @@ -181,17 +187,16 @@ stop_at_entry, error.get()); } - SBProcess sb_process; - ProcessSP process_sp; - if (m_opaque_sp) + + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) launch_flags |= eLaunchFlagDisableASLR; StateType state = eStateInvalid; - process_sp = m_opaque_sp->GetProcessSP(); + process_sp = target_sp->GetProcessSP(); if (process_sp) { state = process_sp->GetState(); @@ -220,9 +225,9 @@ else { if (listener.IsValid()) - process_sp = m_opaque_sp->CreateProcess (listener.ref()); + process_sp = target_sp->CreateProcess (listener.ref()); else - process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); + process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener()); } if (process_sp) @@ -233,7 +238,7 @@ ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); - Module *exe_module = m_opaque_sp->GetExecutableModulePointer(); + Module *exe_module = target_sp->GetExecutableModulePointer(); if (exe_module) launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); if (argv) @@ -258,7 +263,7 @@ { // If we are doing synchronous mode, then wait for the // process to stop yet again! - if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) + if (target_sp->GetDebugger().GetAsyncExecution () == false) process_sp->WaitForProcessToStop (NULL); } } @@ -278,7 +283,7 @@ if (log) { log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", - m_opaque_sp.get(), process_sp.get()); + target_sp.get(), process_sp.get()); } return sb_process; @@ -306,12 +311,13 @@ { SBProcess sb_process; ProcessSP process_sp; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); StateType state = eStateInvalid; - process_sp = m_opaque_sp->GetProcessSP(); + process_sp = target_sp->GetProcessSP(); if (process_sp) { state = process_sp->GetState(); @@ -340,9 +346,9 @@ else { if (listener.IsValid()) - process_sp = m_opaque_sp->CreateProcess (listener.ref()); + process_sp = target_sp->CreateProcess (listener.ref()); else - process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); + process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener()); } if (process_sp) { @@ -353,7 +359,7 @@ error.SetError (process_sp->Attach (attach_info)); // If we are doing synchronous mode, then wait for the // process to stop! - if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) + if (target_sp->GetDebugger().GetAsyncExecution () == false) process_sp->WaitForProcessToStop (NULL); } else @@ -380,12 +386,13 @@ { SBProcess sb_process; ProcessSP process_sp; - if (name && m_opaque_sp) + TargetSP target_sp(GetSP()); + if (name && target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); StateType state = eStateInvalid; - process_sp = m_opaque_sp->GetProcessSP(); + process_sp = target_sp->GetProcessSP(); if (process_sp) { state = process_sp->GetState(); @@ -414,9 +421,9 @@ else { if (listener.IsValid()) - process_sp = m_opaque_sp->CreateProcess (listener.ref()); + process_sp = target_sp->CreateProcess (listener.ref()); else - process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); + process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener()); } if (process_sp) @@ -428,7 +435,7 @@ error.SetError (process_sp->Attach (attach_info)); // If we are doing synchronous mode, then wait for the // process to stop! - if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) + if (target_sp->GetDebugger().GetAsyncExecution () == false) process_sp->WaitForProcessToStop (NULL); } else @@ -455,13 +462,14 @@ { SBProcess sb_process; ProcessSP process_sp; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); if (listener.IsValid()) - process_sp = m_opaque_sp->CreateProcess (listener.ref(), plugin_name); + process_sp = target_sp->CreateProcess (listener.ref(), plugin_name); else - process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name); + process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name); if (process_sp) @@ -486,9 +494,10 @@ { SBFileSpec exe_file_spec; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Module *exe_module = m_opaque_sp->GetExecutableModulePointer(); + Module *exe_module = target_sp->GetExecutableModulePointer(); if (exe_module) exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); } @@ -497,7 +506,7 @@ if (log) { log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", - m_opaque_sp.get(), exe_file_spec.get()); + target_sp.get(), exe_file_spec.get()); } return exe_file_spec; @@ -532,10 +541,11 @@ { lldb::SBAddress sb_addr; Address &addr = sb_addr.ref(); - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr)) + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr)) return sb_addr; } @@ -550,8 +560,12 @@ SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) { SBSymbolContext sc; - if (m_opaque_sp && addr.IsValid()) - m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); + if (addr.IsValid()) + { + TargetSP target_sp(GetSP()); + if (target_sp) + target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); + } return sc; } @@ -568,10 +582,11 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get() && line != 0) + TargetSP target_sp(GetSP()); + if (target_sp && line != 0) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false); } if (log) @@ -581,7 +596,7 @@ char path[PATH_MAX]; sb_file_spec->GetPath (path, sizeof(path)); log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", - m_opaque_sp.get(), + target_sp.get(), path, line, sb_bp.get(), @@ -597,25 +612,26 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get()) + TargetSP target_sp(GetSP()); + if (target_sp.get()) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); if (module_name && module_name[0]) { FileSpecList module_spec_list; module_spec_list.Append (FileSpec (module_name, false)); - *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false); + *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false); } else { - *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false); + *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false); } } if (log) { log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", - m_opaque_sp.get(), symbol_name, module_name, sb_bp.get()); + target_sp.get(), symbol_name, module_name, sb_bp.get()); } return sb_bp; @@ -639,10 +655,11 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get() && symbol_name && symbol_name[0]) + TargetSP target_sp(GetSP()); + if (target_sp && symbol_name && symbol_name[0]) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(), + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + *sb_bp = target_sp->CreateBreakpoint (module_list.get(), comp_unit_list.get(), symbol_name, name_type_mask, @@ -652,7 +669,7 @@ if (log) { log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", - m_opaque_sp.get(), symbol_name, name_type_mask, sb_bp.get()); + target_sp.get(), symbol_name, name_type_mask, sb_bp.get()); } return sb_bp; @@ -665,9 +682,10 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0]) + TargetSP target_sp(GetSP()); + if (target_sp && symbol_name_regex && symbol_name_regex[0]) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); RegularExpression regexp(symbol_name_regex); if (module_name && module_name[0]) @@ -675,18 +693,18 @@ FileSpecList module_spec_list; module_spec_list.Append (FileSpec (module_name, false)); - *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false); + *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false); } else { - *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false); + *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false); } } if (log) { log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", - m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get()); + target_sp.get(), symbol_name_regex, module_name, sb_bp.get()); } return sb_bp; @@ -700,18 +718,19 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0]) + TargetSP target_sp(GetSP()); + if (target_sp && symbol_name_regex && symbol_name_regex[0]) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); RegularExpression regexp(symbol_name_regex); - *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false); + *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false); } if (log) { log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", - m_opaque_sp.get(), symbol_name_regex, sb_bp.get()); + target_sp.get(), symbol_name_regex, sb_bp.get()); } return sb_bp; @@ -723,15 +742,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get()) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - *sb_bp = m_opaque_sp->CreateBreakpoint (address, false); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + *sb_bp = target_sp->CreateBreakpoint (address, false); } if (log) { - log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", m_opaque_sp.get(), (uint64_t) address, sb_bp.get()); + log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get()); } return sb_bp; @@ -743,9 +763,10 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get() && source_regex && source_regex[0]) + TargetSP target_sp(GetSP()); + if (target_sp && source_regex && source_regex[0]) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); RegularExpression regexp(source_regex); FileSpecList source_file_spec_list; source_file_spec_list.Append (source_file.ref()); @@ -755,11 +776,11 @@ FileSpecList module_spec_list; module_spec_list.Append (FileSpec (module_name, false)); - *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false); + *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false); } else { - *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false); + *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false); } } @@ -768,7 +789,7 @@ char path[PATH_MAX]; source_file->GetPath (path, sizeof(path)); log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", - m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get()); + target_sp.get(), source_regex, path, module_name, sb_bp.get()); } return sb_bp; @@ -782,17 +803,18 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_bp; - if (m_opaque_sp.get() && source_regex && source_regex[0]) + TargetSP target_sp(GetSP()); + if (target_sp && source_regex && source_regex[0]) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); RegularExpression regexp(source_regex); - *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false); + *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false); } if (log) { log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", - m_opaque_sp.get(), source_regex, sb_bp.get()); + target_sp.get(), source_regex, sb_bp.get()); } return sb_bp; @@ -801,10 +823,11 @@ uint32_t SBTarget::GetNumBreakpoints () const { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { // The breakpoint list is thread safe, no need to lock - return m_opaque_sp->GetBreakpointList().GetSize(); + return target_sp->GetBreakpointList().GetSize(); } return 0; } @@ -813,10 +836,11 @@ SBTarget::GetBreakpointAtIndex (uint32_t idx) const { SBBreakpoint sb_breakpoint; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { // The breakpoint list is thread safe, no need to lock - *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx); + *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); } return sb_breakpoint; } @@ -827,15 +851,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); bool result = false; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - result = m_opaque_sp->RemoveBreakpointByID (bp_id); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + result = target_sp->RemoveBreakpointByID (bp_id); } if (log) { - log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) bp_id, result); + log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result); } return result; @@ -847,16 +872,17 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBBreakpoint sb_breakpoint; - if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID) + TargetSP target_sp(GetSP()); + if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + *sb_breakpoint = target_sp->GetBreakpointByID (bp_id); } if (log) { log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", - m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); + target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); } return sb_breakpoint; @@ -865,10 +891,11 @@ bool SBTarget::EnableAllBreakpoints () { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - m_opaque_sp->EnableAllBreakpoints (); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + target_sp->EnableAllBreakpoints (); return true; } return false; @@ -877,10 +904,11 @@ bool SBTarget::DisableAllBreakpoints () { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - m_opaque_sp->DisableAllBreakpoints (); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + target_sp->DisableAllBreakpoints (); return true; } return false; @@ -889,10 +917,11 @@ bool SBTarget::DeleteAllBreakpoints () { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - m_opaque_sp->RemoveAllBreakpoints (); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + target_sp->RemoveAllBreakpoints (); return true; } return false; @@ -901,10 +930,11 @@ uint32_t SBTarget::GetNumWatchpoints () const { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { // The watchpoint list is thread safe, no need to lock - return m_opaque_sp->GetWatchpointList().GetSize(); + return target_sp->GetWatchpointList().GetSize(); } return 0; } @@ -913,10 +943,11 @@ SBTarget::GetWatchpointAtIndex (uint32_t idx) const { SBWatchpoint sb_watchpoint; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { // The watchpoint list is thread safe, no need to lock - *sb_watchpoint = m_opaque_sp->GetWatchpointList().GetByIndex(idx); + *sb_watchpoint = target_sp->GetWatchpointList().GetByIndex(idx); } return sb_watchpoint; } @@ -927,15 +958,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); bool result = false; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - result = m_opaque_sp->RemoveWatchpointByID (wp_id); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + result = target_sp->RemoveWatchpointByID (wp_id); } if (log) { - log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) wp_id, result); + log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result); } return result; @@ -947,16 +979,17 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBWatchpoint sb_watchpoint; - if (m_opaque_sp && wp_id != LLDB_INVALID_WATCH_ID) + TargetSP target_sp(GetSP()); + if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - *sb_watchpoint = m_opaque_sp->GetWatchpointList().FindByID(wp_id); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + *sb_watchpoint = target_sp->GetWatchpointList().FindByID(wp_id); } if (log) { log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", - m_opaque_sp.get(), (uint32_t) wp_id, sb_watchpoint.get()); + target_sp.get(), (uint32_t) wp_id, sb_watchpoint.get()); } return sb_watchpoint; @@ -968,18 +1001,19 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBWatchpoint sb_watchpoint; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) | (write ? LLDB_WATCH_TYPE_WRITE : 0); - sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type); + sb_watchpoint = target_sp->CreateWatchpoint(addr, size, watch_type); } if (log) { log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)", - m_opaque_sp.get(), addr, (uint32_t) size, sb_watchpoint.get()); + target_sp.get(), addr, (uint32_t) size, sb_watchpoint.get()); } return sb_watchpoint; @@ -988,10 +1022,11 @@ bool SBTarget::EnableAllWatchpoints () { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - m_opaque_sp->EnableAllWatchpoints (); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + target_sp->EnableAllWatchpoints (); return true; } return false; @@ -1000,10 +1035,11 @@ bool SBTarget::DisableAllWatchpoints () { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - m_opaque_sp->DisableAllWatchpoints (); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + target_sp->DisableAllWatchpoints (); return true; } return false; @@ -1012,10 +1048,11 @@ bool SBTarget::DeleteAllWatchpoints () { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); - m_opaque_sp->RemoveAllWatchpoints (); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + target_sp->RemoveAllWatchpoints (); return true; } return false; @@ -1028,7 +1065,8 @@ const char *uuid_cstr) { lldb::SBModule sb_module; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { FileSpec module_file_spec; UUID module_uuid; @@ -1041,11 +1079,11 @@ module_uuid.SetfromCString(uuid_cstr); if (triple) - module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get()); + module_arch.SetTriple (triple, target_sp->GetPlatform ().get()); - sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec, - module_arch, - uuid_cstr ? &module_uuid : NULL)); + sb_module.SetSP(target_sp->GetSharedModule (module_file_spec, + module_arch, + uuid_cstr ? &module_uuid : NULL)); } return sb_module; } @@ -1053,9 +1091,10 @@ bool SBTarget::AddModule (lldb::SBModule &module) { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp()); + target_sp->GetImages().AppendIfNeeded (module.GetSP()); return true; } return false; @@ -1067,14 +1106,15 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); uint32_t num = 0; - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { // The module list is thread safe, no need to lock - num = m_opaque_sp->GetImages().GetSize(); + num = target_sp->GetImages().GetSize(); } if (log) - log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num); + log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num); return num; } @@ -1095,10 +1135,11 @@ SBTarget::FindModule (const SBFileSpec &sb_file_spec) { SBModule sb_module; - if (m_opaque_sp && sb_file_spec.IsValid()) + TargetSP target_sp(GetSP()); + if (target_sp && sb_file_spec.IsValid()) { // The module list is thread safe, no need to lock - sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL)); + sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL)); } return sb_module; } @@ -1106,17 +1147,19 @@ lldb::ByteOrder SBTarget::GetByteOrder () { - if (m_opaque_sp) - return m_opaque_sp->GetArchitecture().GetByteOrder(); + TargetSP target_sp(GetSP()); + if (target_sp) + return target_sp->GetArchitecture().GetByteOrder(); return eByteOrderInvalid; } const char * SBTarget::GetTriple () { - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - std::string triple (m_opaque_sp->GetArchitecture().GetTriple().str()); + std::string triple (target_sp->GetArchitecture().GetTriple().str()); // Unique the string so we don't run into ownership issues since // the const strings put the string into the string pool once and // the strings never comes out @@ -1129,8 +1172,9 @@ uint32_t SBTarget::GetAddressByteSize() { - if (m_opaque_sp) - return m_opaque_sp->GetArchitecture().GetAddressByteSize(); + TargetSP target_sp(GetSP()); + if (target_sp) + return target_sp->GetArchitecture().GetAddressByteSize(); return sizeof(void*); } @@ -1141,16 +1185,19 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBModule sb_module; - if (m_opaque_sp) + ModuleSP module_sp; + TargetSP target_sp(GetSP()); + if (target_sp) { // The module list is thread safe, no need to lock - sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx)); + module_sp = target_sp->GetImages().GetModuleAtIndex(idx); + sb_module.SetSP (module_sp); } if (log) { log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", - m_opaque_sp.get(), idx, sb_module.get()); + target_sp.get(), idx, module_sp.get()); } return sb_module; @@ -1159,8 +1206,9 @@ bool SBTarget::RemoveModule (lldb::SBModule module) { - if (m_opaque_sp) - return m_opaque_sp->GetImages().Remove(module.get_sp()); + TargetSP target_sp(GetSP()); + if (target_sp) + return target_sp->GetImages().Remove(module.GetSP()); return false; } @@ -1170,11 +1218,12 @@ { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - SBBroadcaster broadcaster(m_opaque_sp.get(), false); + TargetSP target_sp(GetSP()); + SBBroadcaster broadcaster(target_sp.get(), false); if (log) log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", - m_opaque_sp.get(), broadcaster.get()); + target_sp.get(), broadcaster.get()); return broadcaster; } @@ -1185,9 +1234,10 @@ { Stream &strm = description.ref(); - if (m_opaque_sp) + TargetSP target_sp(GetSP()); + if (target_sp) { - m_opaque_sp->Dump (&strm, description_level); + target_sp->Dump (&strm, description_level); } else strm.PutCString ("No value"); @@ -1203,14 +1253,18 @@ { if (!append) sc_list.Clear(); - if (name && m_opaque_sp) + if (name && name[0]) { - const bool symbols_ok = true; - return m_opaque_sp->GetImages().FindFunctions (ConstString(name), - name_type_mask, - symbols_ok, - append, - *sc_list); + TargetSP target_sp(GetSP()); + if (target_sp) + { + const bool symbols_ok = true; + return target_sp->GetImages().FindFunctions (ConstString(name), + name_type_mask, + symbols_ok, + append, + *sc_list); + } } return 0; } @@ -1218,9 +1272,10 @@ lldb::SBType SBTarget::FindFirstType (const char* type) { - if (type && m_opaque_sp) + TargetSP target_sp(GetSP()); + if (type && target_sp) { - size_t count = m_opaque_sp->GetImages().GetSize(); + size_t count = target_sp->GetImages().GetSize(); for (size_t idx = 0; idx < count; idx++) { SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type); @@ -1238,9 +1293,10 @@ SBTypeList retval; - if (type && m_opaque_sp) + TargetSP target_sp(GetSP()); + if (type && target_sp) { - ModuleList& images = m_opaque_sp->GetImages(); + ModuleList& images = target_sp->GetImages(); ConstString name_const(type); SymbolContext sc; TypeList type_list; @@ -1266,20 +1322,21 @@ { SBValueList sb_value_list; - if (name && m_opaque_sp) + TargetSP target_sp(GetSP()); + if (name && target_sp) { VariableList variable_list; const bool append = true; - const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name), - append, - max_matches, - variable_list); + const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name), + append, + max_matches, + variable_list); if (match_count > 0) { - ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get(); + ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); if (exe_scope == NULL) - exe_scope = m_opaque_sp.get(); + exe_scope = target_sp.get(); ValueObjectList &value_object_list = sb_value_list.ref(); for (uint32_t i=0; iGetArchitecture(), + sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), NULL, addr, buf, @@ -1333,8 +1391,8 @@ lldb::addr_t section_base_addr) { SBError sb_error; - - if (IsValid()) + TargetSP target_sp(GetSP()); + if (target_sp) { if (!section.IsValid()) { @@ -1342,7 +1400,7 @@ } else { - m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr); + target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr); } } else @@ -1357,7 +1415,8 @@ { SBError sb_error; - if (IsValid()) + TargetSP target_sp(GetSP()); + if (target_sp) { if (!section.IsValid()) { @@ -1365,7 +1424,7 @@ } else { - m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection()); + target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection()); } } else @@ -1381,15 +1440,13 @@ SBError sb_error; char path[PATH_MAX]; - if (IsValid()) + TargetSP target_sp(GetSP()); + if (target_sp) { - if (!module.IsValid()) - { - sb_error.SetErrorStringWithFormat ("invalid module"); - } - else + ModuleSP module_sp (module.GetSP()); + if (module_sp) { - ObjectFile *objfile = module->GetObjectFile(); + ObjectFile *objfile = module_sp->GetObjectFile(); if (objfile) { SectionList *section_list = objfile->GetSectionList(); @@ -1400,21 +1457,26 @@ { SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); if (section_sp) - m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset); + target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset); } } else { - module->GetFileSpec().GetPath (path, sizeof(path)); + module_sp->GetFileSpec().GetPath (path, sizeof(path)); sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); } } else { - module->GetFileSpec().GetPath (path, sizeof(path)); + module_sp->GetFileSpec().GetPath (path, sizeof(path)); sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); } } + else + { + sb_error.SetErrorStringWithFormat ("invalid module"); + } + } else { @@ -1429,15 +1491,13 @@ SBError sb_error; char path[PATH_MAX]; - if (IsValid()) + TargetSP target_sp(GetSP()); + if (target_sp) { - if (!module.IsValid()) - { - sb_error.SetErrorStringWithFormat ("invalid module"); - } - else + ModuleSP module_sp (module.GetSP()); + if (module_sp) { - ObjectFile *objfile = module->GetObjectFile(); + ObjectFile *objfile = module_sp->GetObjectFile(); if (objfile) { SectionList *section_list = objfile->GetSectionList(); @@ -1448,21 +1508,25 @@ { SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); if (section_sp) - m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get()); + target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get()); } } else { - module->GetFileSpec().GetPath (path, sizeof(path)); + module_sp->GetFileSpec().GetPath (path, sizeof(path)); sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); } } else { - module->GetFileSpec().GetPath (path, sizeof(path)); + module_sp->GetFileSpec().GetPath (path, sizeof(path)); sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); } } + else + { + sb_error.SetErrorStringWithFormat ("invalid module"); + } } else { From gclayton at apple.com Mon Jan 30 13:32:25 2012 From: gclayton at apple.com (Greg Clayton) Date: Mon, 30 Jan 2012 19:32:25 -0000 Subject: [Lldb-commits] [lldb] r149260 - /lldb/trunk/examples/python/sbvalue.py Message-ID: <20120130193225.68F7A2A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 13:32:25 2012 New Revision: 149260 URL: http://llvm.org/viewvc/llvm-project?rev=149260&view=rev Log: Added a new lldb.SBValue helper module that has two classes: sbvalue.value () sbvalue.variable () Initialize both with a lldb.SBValue sbvalue.value() make all sorts of convenience properties. Type "help(sbvalue.value)" in the embedded python interpreter to see what is available. sbvalue.variable() wraps a lldb.SBValue and allows you to play with your variable just as you would expect: pt = sbvalue.variable (lldb.frame.FindVariable("pt")) print pt.x print py.y argv = sbvalue.variable (lldb.frame.FindVariable("argv")) print argv[0] Member access and array acccess is all taken care of! Added: lldb/trunk/examples/python/sbvalue.py (with props) Added: lldb/trunk/examples/python/sbvalue.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/python/sbvalue.py?rev=149260&view=auto ============================================================================== --- lldb/trunk/examples/python/sbvalue.py (added) +++ lldb/trunk/examples/python/sbvalue.py Mon Jan 30 13:32:25 2012 @@ -0,0 +1,255 @@ +#!/usr/bin/python + +import lldb + +class value(object): + '''A class that wraps an lldb.SBValue object and returns an object that + can be used as an object with attribytes:\n + argv = a.value(lldb.frame.FindVariable('argv'))\n + argv.name - return the name of the value that this object contains\n + argv.type - return the lldb.SBType for this value + argv.type_name - return the name of the type + argv.size - return the byte size of this value + argv.is_in_scope - return true if this value is currently in scope + argv.is_pointer - return true if this value is a pointer + argv.format - return the current format for this value + argv.value - return the value's value as a string + argv.summary - return a summary of this value's value + argv.description - return the runtime description for this value + argv.location - return a string that represents the values location (address, register, etc) + argv.target - return the lldb.SBTarget for this value + argv.process - return the lldb.SBProcess for this value + argv.thread - return the lldb.SBThread for this value + argv.frame - return the lldb.SBFrame for this value + argv.num_children - return the number of children this value has + argv.children - return a list of sbvalue objects that represents all of the children of this value + ''' + def __init__(self, sbvalue): + self.sbvalue = sbvalue + + def __nonzero__(self): + return self.sbvalue.__nonzero__() + + def __repr__(self): + return self.sbvalue.__repr__() + + def __str__(self): + return self.sbvalue.__str__() + + def __getitem__(self, key): + if type(key) is int: + return value(self.sbvalue.GetChildAtIndex(key, lldb.eNoDynamicValues, True)) + raise TypeError + + def __getattr__(self, name): + if name == 'name': + return self.sbvalue.GetName() + if name == 'type': + return self.sbvalue.GetType() + if name == 'type_name': + return self.sbvalue.GetTypeName() + if name == 'size': + return self.sbvalue.GetByteSize() + if name == 'is_in_scope': + return self.sbvalue.IsInScope() + if name == 'is_pointer': + return self.sbvalue.TypeIsPointerType() + if name == 'format': + return self.sbvalue.GetFormat () + if name == 'value': + return self.sbvalue.GetValue () + if name == 'summary': + return self.sbvalue.GetSummary () + if name == 'description': + return self.sbvalue.GetObjectDescription () + if name == 'location': + return self.sbvalue.GetLocation () + if name == 'target': + return self.sbvalue.GetTarget() + if name == 'process': + return self.sbvalue.GetProcess() + if name == 'thread': + return self.sbvalue.GetThread() + if name == 'frame': + return self.sbvalue.GetFrame() + if name == 'num_children': + return self.sbvalue.GetNumChildren() + if name == 'children': + # Returns an array of sbvalue objects, one for each child of + # the value for the lldb.SBValue + children = [] + for i in range (self.sbvalue.GetNumChildren()): + children.append(value(self.sbvalue.GetChildAtIndex(i, lldb.eNoDynamicValues, True))) + return children + raise AttributeError + +class variable(object): + '''A class that treats a lldb.SBValue and allows it to be used just as + a variable would be in code. So if you have a Point structure variable + in your code, you would be able to do: "pt.x + pt.y"''' + def __init__(self, sbvalue): + self.sbvalue = sbvalue + + def __nonzero__(self): + return self.sbvalue.__nonzero__() + + def __repr__(self): + return self.sbvalue.__repr__() + + def __str__(self): + return self.sbvalue.__str__() + + def __getitem__(self, key): + # Allow array access if this value has children... + if type(key) is int: + return variable(self.sbvalue.GetValueForExpressionPath("[%i]" % key)) + raise TypeError + + def __getattr__(self, name): + child_sbvalue = self.sbvalue.GetChildMemberWithName (name) + if child_sbvalue: + return variable(child_sbvalue) + raise AttributeError + + def __add__(self, other): + return int(self) + int(other) + + def __sub__(self, other): + return int(self) - int(other) + + def __mul__(self, other): + return int(self) * int(other) + + def __floordiv__(self, other): + return int(self) // int(other) + + def __mod__(self, other): + return int(self) % int(other) + + def __divmod__(self, other): + return int(self) % int(other) + + def __pow__(self, other): + return int(self) ** int(other) + + def __lshift__(self, other): + return int(self) << int(other) + + def __rshift__(self, other): + return int(self) >> int(other) + + def __and__(self, other): + return int(self) & int(other) + + def __xor__(self, other): + return int(self) ^ int(other) + + def __or__(self, other): + return int(self) | int(other) + + def __div__(self, other): + return int(self) / int(other) + + def __truediv__(self, other): + return int(self) / int(other) + + def __iadd__(self, other): + result = self.__add__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __isub__(self, other): + result = self.__sub__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __imul__(self, other): + result = self.__mul__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __idiv__(self, other): + result = self.__div__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __itruediv__(self, other): + result = self.__truediv__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ifloordiv__(self, other): + result = self.__floordiv__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __imod__(self, other): + result = self.__and__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ipow__(self, other): + result = self.__pow__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ipow__(self, other, modulo): + result = self.__pow__(self, other, modulo) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ilshift__(self, other): + result = self.__lshift__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __irshift__(self, other): + result = self.__rshift__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __iand__(self, other): + result = self.__and__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ixor__(self, other): + result = self.__xor__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ior__(self, other): + result = self.__ior__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __neg__(self): + return -int(self) + + def __pos__(self): + return +int(self) + + def __abs__(self): + return abs(int(self)) + + def __invert__(self): + return ~int(self) + + def __complex__(self): + return complex (int(self)) + + def __int__(self): + return self.sbvalue.GetValueAsSigned() + + def __long__(self): + return self.sbvalue.GetValueAsSigned() + + def __float__(self): + return float (self.sbvalue.GetValueAsSigned()) + + def __oct__(self): + return '0%o' % self.sbvalue.GetValueAsSigned() + + def __hex__(self): + return '0x%x' % self.sbvalue.GetValueAsSigned() + \ No newline at end of file Propchange: lldb/trunk/examples/python/sbvalue.py ------------------------------------------------------------------------------ svn:executable = * From johnny.chen at apple.com Mon Jan 30 15:16:22 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 30 Jan 2012 21:16:22 -0000 Subject: [Lldb-commits] [lldb] r149277 - in /lldb/trunk: include/lldb/Breakpoint/BreakpointLocation.h source/Breakpoint/BreakpointLocation.cpp Message-ID: <20120130211622.BFA382A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 15:16:22 2012 New Revision: 149277 URL: http://llvm.org/viewvc/llvm-project?rev=149277&view=rev Log: Make BreakpointLocation::IsEnabled() consistent with the BreakpointLocation::SetEnabled() implementation. Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h?rev=149277&r1=149276&r2=149277&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h (original) +++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h Mon Jan 30 15:16:22 2012 @@ -111,7 +111,7 @@ /// \b true if the breakpoint is enabled, \b false if disabled. //------------------------------------------------------------------ bool - IsEnabled (); + IsEnabled () const; //------------------------------------------------------------------ /// Return the current Ignore Count. Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=149277&r1=149276&r2=149277&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Mon Jan 30 15:16:22 2012 @@ -70,14 +70,12 @@ } bool -BreakpointLocation::IsEnabled () +BreakpointLocation::IsEnabled () const { - if (!m_owner.IsEnabled()) - return false; - else if (m_options_ap.get() != NULL) + if (m_options_ap.get() != NULL) return m_options_ap->IsEnabled(); else - return true; + return m_owner.IsEnabled(); } void @@ -414,7 +412,7 @@ GetID(), GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(), (uint64_t) m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()), - (m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled()) ? "enabled " : "disabled", + IsEnabled() ? "enabled " : "disabled", IsHardware() ? "hardware" : "software", GetHardwareIndex(), GetHitCount(), From johnny.chen at apple.com Mon Jan 30 15:46:17 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 30 Jan 2012 21:46:17 -0000 Subject: [Lldb-commits] [lldb] r149280 - in /lldb/trunk: source/Breakpoint/Watchpoint.cpp source/Commands/CommandObjectWatchpoint.cpp source/Commands/CommandObjectWatchpoint.h test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py test/functionalities/watchpoint/watchpoint_set_command/ test/functionalities/watchpoint/watchpoint_set_command/Makefile test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py test/functionalities/watchpoint/watchpoint_set_command/main.cpp Message-ID: <20120130214617.B41252A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 15:46:17 2012 New Revision: 149280 URL: http://llvm.org/viewvc/llvm-project?rev=149280&view=rev Log: Add "watch set" command as a more general interface in conjunction with "frame var -w". Also add test cases for watching a variable as well as a location expressed as an expression. o TestMyFirstWatchpoint.py: Modified to test "watchpoint set -w write global". o TestWatchLocationWithWatchSet.py: Added to test "watchpoint set -w write -x 1 g_char_ptr + 7" where a contrived example program with several threads is supposed to only access the array index within the range [0..6], but there's some misbehaving thread writing past the range. rdar://problem/10701761 Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/main.cpp Modified: lldb/trunk/source/Breakpoint/Watchpoint.cpp lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp lldb/trunk/source/Commands/CommandObjectWatchpoint.h lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py Modified: lldb/trunk/source/Breakpoint/Watchpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Watchpoint.cpp?rev=149280&r1=149279&r2=149280&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/Watchpoint.cpp (original) +++ lldb/trunk/source/Breakpoint/Watchpoint.cpp Mon Jan 30 15:46:17 2012 @@ -122,7 +122,7 @@ m_watch_write ? "w" : ""); if (description_level >= lldb::eDescriptionLevelFull) { - if (m_decl_str.c_str()) + if (!m_decl_str.empty()) s->Printf("\n declare @ '%s'", m_decl_str.c_str()); if (GetConditionText()) s->Printf("\n condition = '%s'", GetConditionText()); Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=149280&r1=149279&r2=149280&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Mon Jan 30 15:46:17 2012 @@ -16,10 +16,14 @@ #include "lldb/Breakpoint/Watchpoint.h" #include "lldb/Breakpoint/WatchpointList.h" #include "lldb/Core/StreamString.h" +#include "lldb/Core/ValueObject.h" +#include "lldb/Core/ValueObjectVariable.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Target/Target.h" #include "lldb/Interpreter/CommandCompletions.h" +#include "lldb/Symbol/Variable.h" +#include "lldb/Symbol/VariableList.h" +#include "lldb/Target/Target.h" #include @@ -157,6 +161,7 @@ CommandObjectSP delete_command_object (new CommandObjectWatchpointDelete (interpreter)); CommandObjectSP ignore_command_object (new CommandObjectWatchpointIgnore (interpreter)); CommandObjectSP modify_command_object (new CommandObjectWatchpointModify (interpreter)); + CommandObjectSP set_command_object (new CommandObjectWatchpointSet (interpreter)); list_command_object->SetCommandName ("watchpoint list"); enable_command_object->SetCommandName("watchpoint enable"); @@ -164,6 +169,7 @@ delete_command_object->SetCommandName("watchpoint delete"); ignore_command_object->SetCommandName("watchpoint ignore"); modify_command_object->SetCommandName("watchpoint modify"); + set_command_object->SetCommandName("watchpoint set"); status = LoadSubCommand ("list", list_command_object); status = LoadSubCommand ("enable", enable_command_object); @@ -171,6 +177,7 @@ status = LoadSubCommand ("delete", delete_command_object); status = LoadSubCommand ("ignore", ignore_command_object); status = LoadSubCommand ("modify", modify_command_object); + status = LoadSubCommand ("set", set_command_object); } CommandObjectMultiwordWatchpoint::~CommandObjectMultiwordWatchpoint() @@ -844,3 +851,202 @@ return result.Succeeded(); } + +//------------------------------------------------------------------------- +// CommandObjectWatchpointSet +//------------------------------------------------------------------------- +#pragma mark Set + +CommandObjectWatchpointSet::CommandObjectWatchpointSet (CommandInterpreter &interpreter) : + CommandObject (interpreter, + "watchpoint set", + "Set a watchpoint. " + "You can choose to watch a variable in scope with just the '-w' option. " + "If you use the '-x' option to specify the byte size, it is implied " + "that the remaining string is evaluated as an expression with the result " + "interpreted as an address to watch for, i.e., the pointee is watched. " + "If no '-w' option is specified, it defaults to read_write. " + "Note that hardware resources for watching are often limited.", + NULL, + eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), + m_option_group (interpreter), + m_option_watchpoint() +{ + SetHelpLong( +"Examples: \n\ +\n\ + watchpoint set -w read_wriate my_global_var \n\ + # Watch my_global_var for read/write access.\n\ +\n\ + watchpoint set -w write -x 1 foo + 32\n\ + # Watch write access for the 1-byte region pointed to by the address 'foo + 32'.\n"); + + CommandArgumentEntry arg; + CommandArgumentData var_name_arg, expression_arg; + + // Define the first variant of this arg. + var_name_arg.arg_type = eArgTypeVarName; + var_name_arg.arg_repetition = eArgRepeatPlain; + + // Define the second variant of this arg. + expression_arg.arg_type = eArgTypeExpression; + expression_arg.arg_repetition = eArgRepeatPlain; + + // Push the two variants into the argument entry. + arg.push_back (var_name_arg); + arg.push_back (expression_arg); + + // Push the data for the first argument into the m_arguments vector. + m_arguments.push_back (arg); + + m_option_group.Append (&m_option_watchpoint, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1); + m_option_group.Finalize(); +} + +CommandObjectWatchpointSet::~CommandObjectWatchpointSet () +{ +} + +Options * +CommandObjectWatchpointSet::GetOptions () +{ + return &m_option_group; +} + +bool +CommandObjectWatchpointSet::Execute +( + Args& command, + CommandReturnObject &result +) +{ + Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); + ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); + StackFrame *frame = exe_ctx.GetFramePtr(); + if (frame == NULL) + { + result.AppendError ("you must be stopped in a valid stack frame to set a watchpoint."); + result.SetStatus (eReturnStatusFailed); + return false; + } + + // Be careful about the stack frame, if any summary formatter runs code, it might clear the StackFrameList + // for the thread. So hold onto a shared pointer to the frame so it stays alive. + bool get_file_globals = true; + VariableList *variable_list = frame->GetVariableList (get_file_globals); + + bool watch_address = (m_option_watchpoint.watch_size > 0); + + // If no '-w' is specified, default to '-w read_write'. + if (!m_option_watchpoint.watch_variable) + { + m_option_watchpoint.watch_variable = true; + m_option_watchpoint.watch_type = OptionGroupWatchpoint::eWatchReadWrite; + } + // It's possible to specify an address to watch for with the '-x' option. + if (!variable_list && !watch_address) + { + result.GetErrorStream().Printf("error: no variables found, did you forget to use '-x' option to watch an address?\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + // If thre's no argument, it is an error. + if (command.GetArgumentCount() <= 0) { + result.GetErrorStream().Printf("error: specify your target variable (no '-x') or expression (with '-x') to watch for\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // We passed the sanity check for the options. + // Proceed to set the watchpoint now. + lldb::addr_t addr = 0; + size_t size = 0; + + VariableSP var_sp; + ValueObjectSP valobj_sp; + Stream &output_stream = result.GetOutputStream(); + + if (watch_address) { + std::string expr_str; + command.GetQuotedCommandString(expr_str); + const bool coerce_to_id = true; + const bool unwind_on_error = true; + const bool keep_in_memory = false; + ExecutionResults expr_result = target->EvaluateExpression (expr_str.c_str(), + frame, + eExecutionPolicyOnlyWhenNeeded, + coerce_to_id, + unwind_on_error, + keep_in_memory, + eNoDynamicValues, + valobj_sp); + if (expr_result != eExecutionCompleted) { + result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n"); + result.SetStatus(eReturnStatusFailed); + } + + // Get the address to watch. + addr = valobj_sp->GetValueAsUnsigned(0); + if (!addr) { + result.GetErrorStream().Printf("error: expression did not evaluate to an address\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + size = m_option_watchpoint.watch_size; + } else { + // A simple watch variable gesture allows only one argument. + if (m_option_watchpoint.watch_size == 0 && command.GetArgumentCount() != 1) { + result.GetErrorStream().Printf("error: specify exactly one variable with the '-w' option, i.e., no '-x'\n"); + result.SetStatus(eReturnStatusFailed); + return false; + } + + // Things have checked out ok... + Error error; + uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; + valobj_sp = frame->GetValueForVariableExpressionPath (command.GetArgumentAtIndex(0), + eNoDynamicValues, + expr_path_options, + var_sp, + error); + if (valobj_sp) { + AddressType addr_type; + addr = valobj_sp->GetAddressOf(false, &addr_type); + if (addr_type == eAddressTypeLoad) { + // We're in business. + // Find out the size of this variable. + size = valobj_sp->GetByteSize(); + } + } else { + const char *error_cstr = error.AsCString(NULL); + if (error_cstr) + result.GetErrorStream().Printf("error: %s\n", error_cstr); + else + result.GetErrorStream().Printf ("error: unable to find any variable expression path that matches '%s'\n", + command.GetArgumentAtIndex(0)); + return false; + } + } + + // Now it's time to create the watchpoint. + uint32_t watch_type = m_option_watchpoint.watch_type; + Watchpoint *wp = exe_ctx.GetTargetRef().CreateWatchpoint(addr, size, watch_type).get(); + if (wp) { + if (var_sp && var_sp->GetDeclaration().GetFile()) { + StreamString ss; + // True to show fullpath for declaration file. + var_sp->GetDeclaration().DumpStopContext(&ss, true); + wp->SetDeclInfo(ss.GetString()); + } + StreamString ss; + output_stream.Printf("Watchpoint created: "); + wp->GetDescription(&output_stream, lldb::eDescriptionLevelFull); + output_stream.EOL(); + result.SetStatus(eReturnStatusSuccessFinishResult); + } else { + result.AppendErrorWithFormat("Watchpoint creation failed.\n"); + result.SetStatus(eReturnStatusFailed); + } + + return result.Succeeded(); +} Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.h?rev=149280&r1=149279&r2=149280&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectWatchpoint.h (original) +++ lldb/trunk/source/Commands/CommandObjectWatchpoint.h Mon Jan 30 15:46:17 2012 @@ -17,6 +17,7 @@ // Project includes #include "lldb/Interpreter/CommandObjectMultiword.h" #include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/OptionGroupWatchpoint.h" namespace lldb_private { @@ -242,6 +243,31 @@ CommandOptions m_options; }; +//------------------------------------------------------------------------- +// CommandObjectWatchpointSet +//------------------------------------------------------------------------- + +class CommandObjectWatchpointSet : public CommandObject +{ +public: + + CommandObjectWatchpointSet (CommandInterpreter &interpreter); + + virtual + ~CommandObjectWatchpointSet (); + + virtual bool + Execute (Args& command, + CommandReturnObject &result); + + virtual Options * + GetOptions (); + +private: + OptionGroupOptions m_option_group; + OptionGroupWatchpoint m_option_watchpoint; +}; + } // namespace lldb_private #endif // liblldb_CommandObjectWatchpoint_h_ Modified: lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py?rev=149280&r1=149279&r2=149280&view=diff ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py (original) +++ lldb/trunk/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py Mon Jan 30 15:46:17 2012 @@ -12,18 +12,30 @@ mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint") @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") - def test_hello_watchpoint_with_dsym(self): + def test_hello_watchpoint_with_dsym_using_frame_var(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDsym(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() - def test_hello_watchpoint_with_dwarf(self): + def test_hello_watchpoint_with_dwarf_using_frame_var(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDwarf(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() + def test_hello_watchpoint_with_dsym_using_watchpoint_set(self): + """Test a simple sequence of watchpoint creation and watchpoint hit.""" + self.buildDsym(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + self.hello_watchpoint(use_frame_var=False) + + def test_hello_watchpoint_with_dwarf_using_watchpoint_set(self): + """Test a simple sequence of watchpoint creation and watchpoint hit.""" + self.buildDwarf(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + self.hello_watchpoint(use_frame_var=False) + def setUp(self): # Call super's setUp(). TestBase.setUp(self) @@ -37,7 +49,7 @@ self.exe_name = self.testMethodName self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - def hello_watchpoint(self): + def hello_watchpoint(self, use_frame_var=True): """Test a simple sequence of watchpoint creation and watchpoint hit.""" exe = os.path.join(os.getcwd(), self.exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) @@ -58,9 +70,14 @@ # Now let's set a write-type watchpoint for 'global'. # There should be only one watchpoint hit (see main.c). - self.expect("frame variable -w write -g -L global", WATCHPOINT_CREATED, - substrs = ['Watchpoint created', 'size = 4', 'type = w', - '%s:%d' % (self.source, self.decl)]) + if use_frame_var: + self.expect("frame variable -w write -g -L global", WATCHPOINT_CREATED, + substrs = ['Watchpoint created', 'size = 4', 'type = w', + '%s:%d' % (self.source, self.decl)]) + else: + self.expect("watchpoint set -w write global", WATCHPOINT_CREATED, + substrs = ['Watchpoint created', 'size = 4', 'type = w', + '%s:%d' % (self.source, self.decl)]) # Use the '-v' option to do verbose listing of the watchpoint. # The hit count should be 0 initially. Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile?rev=149280&view=auto ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile (added) +++ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/Makefile Mon Jan 30 15:46:17 2012 @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py?rev=149280&view=auto ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py (added) +++ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py Mon Jan 30 15:46:17 2012 @@ -0,0 +1,102 @@ +""" +Test lldb watchpoint that uses '-x size' to watch a pointed location with size. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class WatchLocationUsingWatchpointSetTestCase(TestBase): + + mydir = os.path.join("functionalities", "watchpoint", "watchpoint_set_command") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_watchlocation_with_dsym_using_watchpoint_set(self): + """Test watching a location with 'watchpoint set -w write -x size' option.""" + self.buildDsym(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + self.watchlocation_using_watchpoint_set() + + def test_watchlocation_with_dwarf_using_watchpoint_set(self): + """Test watching a location with 'watchpoint set -w write -x size' option.""" + self.buildDwarf(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + self.watchlocation_using_watchpoint_set() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.line = line_number(self.source, '// Set break point at this line.') + # This is for verifying that watch location works. + self.violating_func = "do_bad_thing_with_location"; + # Build dictionary to have unique executable names for each test method. + self.exe_name = self.testMethodName + self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} + + def watchlocation_using_watchpoint_set(self): + """Test watching a location with '-x size' option.""" + exe = os.path.join(os.getcwd(), self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" % + (self.source, self.line)) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # Now let's set a write-type watchpoint pointed to by 'g_char_ptr' and + # with offset as 7. + # The main.cpp, by design, misbehaves by not following the agreed upon + # protocol of only accessing the allowable index range of [0, 6]. + self.expect("watchpoint set -w write -x 1 g_char_ptr + 7", WATCHPOINT_CREATED, + substrs = ['Watchpoint created', 'size = 1', 'type = w']) + self.runCmd("expr unsigned val = *g_char_ptr; val") + self.expect(self.res.GetOutput().splitlines()[0], exe=False, + endstr = ' = 0') + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should be 0 initially. + self.expect("watchpoint list -v", + substrs = ['hit_count = 0']) + + self.runCmd("process continue") + + # We should be stopped again due to the watchpoint (write type), but + # only once. The stop reason of the thread should be watchpoint. + self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, + substrs = ['stopped', + 'stop reason = watchpoint', + self.violating_func]) + + # Switch to the thread stopped due to watchpoint and issue some commands. + self.switch_to_thread_with_stop_reason(lldb.eStopReasonWatchpoint) + self.runCmd("thread backtrace") + self.runCmd("expr unsigned val = g_char_ptr[7]; val") + self.expect(self.res.GetOutput().splitlines()[0], exe=False, + endstr = ' = 99') + + # Use the '-v' option to do verbose listing of the watchpoint. + # The hit count should now be 1. + self.expect("watchpoint list -v", + substrs = ['hit_count = 1']) + + self.runCmd("thread backtrace all") + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/main.cpp?rev=149280&view=auto ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/main.cpp (added) +++ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/main.cpp Mon Jan 30 15:46:17 2012 @@ -0,0 +1,109 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// C includes +#include +#include +#include +#include +#include + +pthread_t g_thread_1 = NULL; +pthread_t g_thread_2 = NULL; +pthread_t g_thread_3 = NULL; + +char *g_char_ptr = NULL; + +void +do_bad_thing_with_location(unsigned index, char *char_ptr, char new_val) +{ + unsigned what = new_val; + printf("new value written to array(%p) and index(%u) = %u\n", char_ptr, index, what); + char_ptr[index] = new_val; +} + +uint32_t access_pool (uint32_t flag = 0); + +uint32_t +access_pool (uint32_t flag) +{ + static pthread_mutex_t g_access_mutex = PTHREAD_MUTEX_INITIALIZER; + static unsigned idx = 0; // Well-behaving thread only writes into indexs from 0..6. + if (flag == 0) + ::pthread_mutex_lock (&g_access_mutex); + + // idx valid range is [0, 6]. + if (idx > 6) + idx = 0; + + if (flag != 0) { + // Write into a forbidden area. + do_bad_thing_with_location(7, g_char_ptr, 99); + } + + unsigned index = idx++; + + if (flag == 0) + ::pthread_mutex_unlock (&g_access_mutex); + return g_char_ptr[index]; +} + +void * +thread_func (void *arg) +{ + uint32_t thread_index = *((uint32_t *)arg); + printf ("%s (thread index = %u) startng...\n", __FUNCTION__, thread_index); + + uint32_t count = 0; + uint32_t val; + while (count++ < 15) + { + // random micro second sleep from zero to 3 seconds + int usec = ::rand() % 3000000; + printf ("%s (thread = %u) doing a usleep (%d)...\n", __FUNCTION__, thread_index, usec); + ::usleep (usec); + + if (count < 7) + val = access_pool (); + else + val = access_pool (1); + + printf ("%s (thread = %u) after usleep access_pool returns %d (count=%d)...\n", __FUNCTION__, thread_index, val, count); + } + printf ("%s (thread index = %u) exiting...\n", __FUNCTION__, thread_index); + return NULL; +} + + +int main (int argc, char const *argv[]) +{ + int err; + void *thread_result = NULL; + uint32_t thread_index_1 = 1; + uint32_t thread_index_2 = 2; + uint32_t thread_index_3 = 3; + + g_char_ptr = (char *)malloc (10); + for (int i = 0; i < 10; ++i) + *g_char_ptr = 0; + + // Create 3 threads + err = ::pthread_create (&g_thread_1, NULL, thread_func, &thread_index_1); + err = ::pthread_create (&g_thread_2, NULL, thread_func, &thread_index_2); + err = ::pthread_create (&g_thread_3, NULL, thread_func, &thread_index_3); + + printf ("Before turning all three threads loose...\n"); // Set break point at this line. + + // Join all of our threads + err = ::pthread_join (g_thread_1, &thread_result); + err = ::pthread_join (g_thread_2, &thread_result); + err = ::pthread_join (g_thread_3, &thread_result); + + return 0; +} From johnny.chen at apple.com Mon Jan 30 16:48:11 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 30 Jan 2012 22:48:11 -0000 Subject: [Lldb-commits] [lldb] r149292 - in /lldb/trunk: include/lldb/Breakpoint/BreakpointLocation.h source/Breakpoint/BreakpointLocation.cpp Message-ID: <20120130224811.1BE9C2A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 16:48:10 2012 New Revision: 149292 URL: http://llvm.org/viewvc/llvm-project?rev=149292&view=rev Log: Reverted 149277 changeset. It was coded that way for a reason. Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h?rev=149292&r1=149291&r2=149292&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h (original) +++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h Mon Jan 30 16:48:10 2012 @@ -111,7 +111,7 @@ /// \b true if the breakpoint is enabled, \b false if disabled. //------------------------------------------------------------------ bool - IsEnabled () const; + IsEnabled (); //------------------------------------------------------------------ /// Return the current Ignore Count. Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=149292&r1=149291&r2=149292&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Mon Jan 30 16:48:10 2012 @@ -70,12 +70,14 @@ } bool -BreakpointLocation::IsEnabled () const +BreakpointLocation::IsEnabled () { - if (m_options_ap.get() != NULL) + if (!m_owner.IsEnabled()) + return false; + else if (m_options_ap.get() != NULL) return m_options_ap->IsEnabled(); else - return m_owner.IsEnabled(); + return true; } void @@ -412,7 +414,7 @@ GetID(), GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(), (uint64_t) m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()), - IsEnabled() ? "enabled " : "disabled", + (m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled()) ? "enabled " : "disabled", IsHardware() ? "hardware" : "software", GetHardwareIndex(), GetHitCount(), From johnny.chen at apple.com Mon Jan 30 17:17:07 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 30 Jan 2012 23:17:07 -0000 Subject: [Lldb-commits] [lldb] r149295 - /lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py Message-ID: <20120130231707.CA1922A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 17:17:07 2012 New Revision: 149295 URL: http://llvm.org/viewvc/llvm-project?rev=149295&view=rev Log: Fixed a typo in the test case. Updated comment. Modified: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py Modified: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py?rev=149295&r1=149294&r2=149295&view=diff ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py (original) +++ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchLocationWithWatchSet.py Mon Jan 30 17:17:07 2012 @@ -1,5 +1,5 @@ """ -Test lldb watchpoint that uses '-x size' to watch a pointed location with size. +Test lldb watchpoint that uses 'watchpoint set -w write -x size' to watch a pointed location with size. """ import os, time @@ -62,7 +62,7 @@ # protocol of only accessing the allowable index range of [0, 6]. self.expect("watchpoint set -w write -x 1 g_char_ptr + 7", WATCHPOINT_CREATED, substrs = ['Watchpoint created', 'size = 1', 'type = w']) - self.runCmd("expr unsigned val = *g_char_ptr; val") + self.runCmd("expr unsigned val = g_char_ptr[7]; val") self.expect(self.res.GetOutput().splitlines()[0], exe=False, endstr = ' = 0') From johnny.chen at apple.com Mon Jan 30 17:26:57 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 30 Jan 2012 23:26:57 -0000 Subject: [Lldb-commits] [lldb] r149297 - /lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Message-ID: <20120130232657.EC0C02A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 17:26:57 2012 New Revision: 149297 URL: http://llvm.org/viewvc/llvm-project?rev=149297&view=rev Log: Trivial indentation change. Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=149297&r1=149296&r2=149297&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Mon Jan 30 17:26:57 2012 @@ -951,7 +951,8 @@ return false; } // If thre's no argument, it is an error. - if (command.GetArgumentCount() <= 0) { + if (command.GetArgumentCount() <= 0) + { result.GetErrorStream().Printf("error: specify your target variable (no '-x') or expression (with '-x') to watch for\n"); result.SetStatus(eReturnStatusFailed); return false; From johnny.chen at apple.com Mon Jan 30 18:38:04 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 31 Jan 2012 00:38:04 -0000 Subject: [Lldb-commits] [lldb] r149304 - /lldb/trunk/test/dotest.py Message-ID: <20120131003804.13D552A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 18:38:03 2012 New Revision: 149304 URL: http://llvm.org/viewvc/llvm-project?rev=149304&view=rev Log: Add a '-u ENV_VAR_NAME' option to the test driver, whose purpose is to unset the said environment variable before starting the test runner which executes the test cases and may spawn child processes. An example: ./dotest.py -u MY_ENV1 -u MY_ENV2 -v -p TestWatchLocationWithWatchSet.py Modified: lldb/trunk/test/dotest.py Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=149304&r1=149303&r2=149304&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Mon Jan 30 18:38:03 2012 @@ -161,6 +161,9 @@ # svn_info stores the output from 'svn info lldb.base.dir'. svn_info = '' +# The environment variables to unset before running the test cases. +unsets = [] + # Default verbosity is 0. verbose = 0 @@ -229,6 +232,8 @@ with errored or failed status; if not specified, the test driver uses the timestamp as the session dir name -t : turn on tracing of lldb command and other detailed test executions +-u : specify an environment variable to unset before running the test cases + e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble' -v : do verbose mode of unittest framework (print out each test case invocation) -X : exclude a directory from consideration for test discovery -X types => if 'types' appear in the pathname components of a potential testfile @@ -362,6 +367,7 @@ global regexp global rdir global sdir_name + global unsets global verbose global testdirs @@ -503,6 +509,13 @@ elif sys.argv[index].startswith('-t'): os.environ["LLDB_COMMAND_TRACE"] = "YES" index += 1 + elif sys.argv[index].startswith('-u'): + # Increment by 1 to fetch the environment variable to unset. + index += 1 + if index >= len(sys.argv) or sys.argv[index].startswith('-'): + usage() + unsets.append(sys.argv[index]) + index += 1 elif sys.argv[index].startswith('-v'): verbose = 2 index += 1 @@ -1009,6 +1022,16 @@ print >> f, "Command invoked: %s\n" % getMyCommandLine() # +# If we have environment variables to unset, do it here before we invoke the test runner. +# +for env_var in unsets : + if env_var in os.environ: + # From Python Doc: When unsetenv() is supported, deletion of items in os.environ + # is automatically translated into a corresponding call to unsetenv() + del os.environ[env_var] + #os.unsetenv(env_var) + +# # Invoke the default TextTestRunner to run the test suite, possibly iterating # over different configurations. # From johnny.chen at apple.com Mon Jan 30 18:48:02 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 31 Jan 2012 00:48:02 -0000 Subject: [Lldb-commits] [lldb] r149305 - /lldb/trunk/test/dotest.py Message-ID: <20120131004802.57D442A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 18:48:02 2012 New Revision: 149305 URL: http://llvm.org/viewvc/llvm-project?rev=149305&view=rev Log: Add a period. Modified: lldb/trunk/test/dotest.py Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=149305&r1=149304&r2=149305&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Mon Jan 30 18:48:02 2012 @@ -1027,7 +1027,7 @@ for env_var in unsets : if env_var in os.environ: # From Python Doc: When unsetenv() is supported, deletion of items in os.environ - # is automatically translated into a corresponding call to unsetenv() + # is automatically translated into a corresponding call to unsetenv(). del os.environ[env_var] #os.unsetenv(env_var) From johnny.chen at apple.com Mon Jan 30 19:26:28 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 31 Jan 2012 01:26:28 -0000 Subject: [Lldb-commits] [lldb] r149324 - in /lldb/trunk/test/functionalities: completion/TestCompletion.py watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py Message-ID: <20120131012628.D45852A6C12C@llvm.org> Author: johnny Date: Mon Jan 30 19:26:28 2012 New Revision: 149324 URL: http://llvm.org/viewvc/llvm-project?rev=149324&view=rev Log: Add some more test cases for the "watchpoint set" command. Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py Modified: lldb/trunk/test/functionalities/completion/TestCompletion.py Modified: lldb/trunk/test/functionalities/completion/TestCompletion.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/completion/TestCompletion.py?rev=149324&r1=149323&r2=149324&view=diff ============================================================================== --- lldb/trunk/test/functionalities/completion/TestCompletion.py (original) +++ lldb/trunk/test/functionalities/completion/TestCompletion.py Mon Jan 30 19:26:28 2012 @@ -26,10 +26,22 @@ """Test that 'frame variable -w ' completes to ['Available completions:', 'read', 'write', 'read_write'].""" self.complete_from_to('frame variable -w ', ['Available completions:', 'read', 'write', 'read_write']) + def test_watchpoint_set_dash_x(self): + """Test that 'watchpoint set -x' completes to 'watchpoint set -x '.""" + self.complete_from_to('watchpoint set -x', 'watchpoint set -x ') + + def test_watchpoint_set_dash_w_read_underbar(self): + """Test that 'watchpoint set -w read_' completes to 'watchpoint set -w read_write'.""" + self.complete_from_to('watchpoint set -w read_', 'watchpoint set -w read_write') + def test_help_fi(self): """Test that 'help fi' completes to ['Available completions:', 'file', 'finish'].""" self.complete_from_to('help fi', ['Available completions:', 'file', 'finish']) + def test_help_watchpoint_s(self): + """Test that 'help watchpoint s' completes to 'help watchpoint set '.""" + self.complete_from_to('help watchpoint s', 'help watchpoint set ') + def test_settings_append_target_er(self): """Test that 'settings append target.er' completes to 'settings append target.error-path'.""" self.complete_from_to('settings append target.er', 'settings append target.error-path') Added: lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py?rev=149324&view=auto ============================================================================== --- lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py (added) +++ lldb/trunk/test/functionalities/watchpoint/watchpoint_set_command/TestWatchpointSetErrorCases.py Mon Jan 30 19:26:28 2012 @@ -0,0 +1,67 @@ +""" +Test error cases for the 'watchpoint set' command to make sure it errors out when necessary. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class WatchpointSetErrorTestCase(TestBase): + + mydir = os.path.join("functionalities", "watchpoint", "watchpoint_set_command") + + def test_error_cases_with_watchpoint_set(self): + """Test error cases with the 'watchpoint set' command.""" + self.buildDwarf(dictionary=self.d) + self.setTearDownCleanup(dictionary=self.d) + self.error_cases_with_watchpoint_set() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Our simple source filename. + self.source = 'main.cpp' + # Find the line number to break inside main(). + self.line = line_number(self.source, '// Set break point at this line.') + # Build dictionary to have unique executable names for each test method. + self.exe_name = self.testMethodName + self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} + + def error_cases_with_watchpoint_set(self): + """Test error cases with the 'watchpoint set' command.""" + exe = os.path.join(os.getcwd(), self.exe_name) + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Add a breakpoint to set a watchpoint when stopped on the breakpoint. + self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" % + (self.source, self.line)) + + # Run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # We should be stopped again due to the breakpoint. + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # Try some error conditions: + + # No argument is an error. + self.expect("watchpoint set", error=True, + substrs = ['specify your target variable', + 'or expression', + 'to watch for']) + + # Wrong size parameter is an error. + self.expect("watchpoint set -x -128", error=True, + substrs = ['invalid enumeration value']) + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() From granata.enrico at gmail.com Mon Jan 30 20:21:46 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Tue, 31 Jan 2012 02:21:46 -0000 Subject: [Lldb-commits] [lldb] r149338 - /lldb/trunk/source/Commands/CommandObjectType.cpp Message-ID: <20120131022146.146132A6C12C@llvm.org> Author: enrico Date: Mon Jan 30 20:21:45 2012 New Revision: 149338 URL: http://llvm.org/viewvc/llvm-project?rev=149338&view=rev Log: quick fixes for two issues that were causing LLDB to crash Modified: lldb/trunk/source/Commands/CommandObjectType.cpp Modified: lldb/trunk/source/Commands/CommandObjectType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=149338&r1=149337&r2=149338&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectType.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectType.cpp Mon Jan 30 20:21:45 2012 @@ -929,8 +929,11 @@ } else { - out_stream->PutCString (error.AsCString()); - out_stream->Flush(); + if (error.AsCString()) + { + out_stream->PutCString (error.AsCString()); + out_stream->Flush(); + } return; } } @@ -1571,7 +1574,7 @@ if (m_options.m_delete_all) { - DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)typeCS.GetCString()); + DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS); result.SetStatus(eReturnStatusSuccessFinishNoResult); return result.Succeeded(); } From gclayton at apple.com Mon Jan 30 22:25:15 2012 From: gclayton at apple.com (Greg Clayton) Date: Tue, 31 Jan 2012 04:25:15 -0000 Subject: [Lldb-commits] [lldb] r149345 - /lldb/trunk/source/API/SBValue.cpp Message-ID: <20120131042515.AF3E52A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 22:25:15 2012 New Revision: 149345 URL: http://llvm.org/viewvc/llvm-project?rev=149345&view=rev Log: Fixed an issue where we can crash if you call cast when the SBValue doesn't contain a valid value. Modified: lldb/trunk/source/API/SBValue.cpp Modified: lldb/trunk/source/API/SBValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=149345&r1=149344&r2=149345&view=diff ============================================================================== --- lldb/trunk/source/API/SBValue.cpp (original) +++ lldb/trunk/source/API/SBValue.cpp Mon Jan 30 22:25:15 2012 @@ -377,7 +377,10 @@ lldb::SBValue SBValue::Cast (SBType type) { - return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type); + lldb::SBValue sb_value; + if (m_opaque_sp) + sb_value = CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type); + return sb_value; } lldb::SBValue From gclayton at apple.com Mon Jan 30 22:35:00 2012 From: gclayton at apple.com (Greg Clayton) Date: Tue, 31 Jan 2012 04:35:00 -0000 Subject: [Lldb-commits] [lldb] r149346 - in /lldb/tags/lldb-109: include/lldb/Core/ConnectionFileDescriptor.h include/lldb/Target/Thread.h include/lldb/Target/ThreadList.h source/API/SBValue.cpp source/Core/Communication.cpp source/Core/ConnectionFileDescriptor.cpp source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp source/Target/Process.cpp source/Target/ThreadList.cpp tools/driver/Driver.cpp Message-ID: <20120131043501.1AB632A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 22:35:00 2012 New Revision: 149346 URL: http://llvm.org/viewvc/llvm-project?rev=149346&view=rev Log: Fixed an issue with closing debug sessions down where we might end up double closing a file descriptor. Previously we had a mutex in a class that was being used in a read thread, and the main thread would come along and cancel the thread during the file close and the thread would exit without releasing the mutex and cause deadlocks. I solved the issue by not canceling the read thread and closing all needed file descriptors. Modified: lldb/tags/lldb-109/include/lldb/Core/ConnectionFileDescriptor.h lldb/tags/lldb-109/include/lldb/Target/Thread.h lldb/tags/lldb-109/include/lldb/Target/ThreadList.h lldb/tags/lldb-109/source/API/SBValue.cpp lldb/tags/lldb-109/source/Core/Communication.cpp lldb/tags/lldb-109/source/Core/ConnectionFileDescriptor.cpp lldb/tags/lldb-109/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp lldb/tags/lldb-109/source/Target/Process.cpp lldb/tags/lldb-109/source/Target/ThreadList.cpp lldb/tags/lldb-109/tools/driver/Driver.cpp Modified: lldb/tags/lldb-109/include/lldb/Core/ConnectionFileDescriptor.h URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/include/lldb/Core/ConnectionFileDescriptor.h?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/include/lldb/Core/ConnectionFileDescriptor.h (original) +++ lldb/tags/lldb-109/include/lldb/Core/ConnectionFileDescriptor.h Mon Jan 30 22:35:00 2012 @@ -105,7 +105,7 @@ SocketAddress m_udp_send_sockaddr; bool m_should_close_fd; // True if this class should close the file descriptor when it goes away. uint32_t m_socket_timeout_usec; - //Mutex m_mutex; + Mutex m_mutex; static in_port_t GetSocketPort (int fd); Modified: lldb/tags/lldb-109/include/lldb/Target/Thread.h URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/include/lldb/Target/Thread.h?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/include/lldb/Target/Thread.h (original) +++ lldb/tags/lldb-109/include/lldb/Target/Thread.h Mon Jan 30 22:35:00 2012 @@ -769,6 +769,7 @@ protected: friend class ThreadPlan; + friend class ThreadList; friend class StackFrameList; // This is necessary to make sure thread assets get destroyed while the thread is still in good shape Modified: lldb/tags/lldb-109/include/lldb/Target/ThreadList.h URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/include/lldb/Target/ThreadList.h?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/include/lldb/Target/ThreadList.h (original) +++ lldb/tags/lldb-109/include/lldb/Target/ThreadList.h Mon Jan 30 22:35:00 2012 @@ -59,6 +59,9 @@ void Clear(); + void + Destroy(); + // Note that "idx" is not the same as the "thread_index". It is a zero // based index to accessing the current threads, whereas "thread_index" // is a unique index assigned Modified: lldb/tags/lldb-109/source/API/SBValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/source/API/SBValue.cpp?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/source/API/SBValue.cpp (original) +++ lldb/tags/lldb-109/source/API/SBValue.cpp Mon Jan 30 22:35:00 2012 @@ -375,7 +375,10 @@ lldb::SBValue SBValue::Cast (SBType type) { - return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type); + lldb::SBValue sb_value; + if (m_opaque_sp) + sb_value = CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type); + return sb_value; } lldb::SBValue @@ -1146,14 +1149,14 @@ SBValue::Watch (bool resolve_location, bool read, bool write) { lldb::SBWatchpoint sb_watchpoint; - if (!m_opaque_sp) - return sb_watchpoint; - - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + if (m_opaque_sp) { - Mutex::Locker api_locker (target->GetAPIMutex()); - sb_watchpoint = WatchValue(read, write, false); + Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); + if (target) + { + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_watchpoint = WatchValue(read, write, false); + } } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -1166,14 +1169,14 @@ SBValue::WatchPointee (bool resolve_location, bool read, bool write) { lldb::SBWatchpoint sb_watchpoint; - if (!m_opaque_sp) - return sb_watchpoint; - - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + if (m_opaque_sp) { - Mutex::Locker api_locker (target->GetAPIMutex()); - sb_watchpoint = WatchValue(read, write, true); + Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); + if (target) + { + Mutex::Locker api_locker (target->GetAPIMutex()); + sb_watchpoint = WatchValue(read, write, true); + } } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) Modified: lldb/tags/lldb-109/source/Core/Communication.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/source/Core/Communication.cpp?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/source/Core/Communication.cpp (original) +++ lldb/tags/lldb-109/source/Core/Communication.cpp Mon Jan 30 22:35:00 2012 @@ -65,8 +65,8 @@ Communication::Clear() { SetReadThreadBytesReceivedCallback (NULL, NULL); - StopReadThread (NULL); Disconnect (NULL); + StopReadThread (NULL); } ConnectionStatus @@ -253,7 +253,7 @@ BroadcastEvent (eBroadcastBitReadThreadShouldExit, NULL); - Host::ThreadCancel (m_read_thread, error_ptr); + //Host::ThreadCancel (m_read_thread, error_ptr); bool status = Host::ThreadJoin (m_read_thread, NULL, error_ptr); m_read_thread = LLDB_INVALID_HOST_THREAD; @@ -383,7 +383,8 @@ // Let clients know that this thread is exiting comm->BroadcastEvent (eBroadcastBitReadThreadDidExit); comm->m_read_thread_enabled = false; - comm->Disconnect(); + comm->m_read_thread = LLDB_INVALID_HOST_THREAD; +// comm->Disconnect(); return NULL; } @@ -401,8 +402,8 @@ void Communication::SetConnection (Connection *connection) { - StopReadThread(NULL); Disconnect (NULL); + StopReadThread(NULL); m_connection_sp.reset(connection); } Modified: lldb/tags/lldb-109/source/Core/ConnectionFileDescriptor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/source/Core/ConnectionFileDescriptor.cpp?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/source/Core/ConnectionFileDescriptor.cpp (original) +++ lldb/tags/lldb-109/source/Core/ConnectionFileDescriptor.cpp Mon Jan 30 22:35:00 2012 @@ -31,7 +31,7 @@ #include "lldb/Core/Log.h" #include "lldb/Core/RegularExpression.h" #include "lldb/Core/Timer.h" - +#include "lldb/Host/Host.h" using namespace lldb; using namespace lldb_private; @@ -73,8 +73,8 @@ m_fd_recv_type (eFDTypeFile), m_udp_send_sockaddr (), m_should_close_fd (false), - m_socket_timeout_usec(0)//, - //m_mutex (Mutex::eMutexTypeRecursive) + m_socket_timeout_usec(0), + m_mutex (Mutex::eMutexTypeRecursive) { LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) @@ -89,7 +89,8 @@ m_fd_recv_type (eFDTypeFile), m_udp_send_sockaddr (), m_should_close_fd (owns_fd), - m_socket_timeout_usec(0) + m_socket_timeout_usec(0), + m_mutex (Mutex::eMutexTypeRecursive) { LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) @@ -114,7 +115,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr) { - //Mutex::Locker locker (m_mutex); + Mutex::Locker locker (m_mutex); LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); if (log) log->Printf ("%p ConnectionFileDescriptor::Connect (url = '%s')", this, s); @@ -234,6 +235,7 @@ ConnectionStatus ConnectionFileDescriptor::Disconnect (Error *error_ptr) { + Mutex::Locker locker (m_mutex); LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); if (log) log->Printf ("%p ConnectionFileDescriptor::Disconnect ()", this); @@ -243,22 +245,25 @@ return eConnectionStatusSuccess; } ConnectionStatus status = eConnectionStatusSuccess; - if (m_fd_send == m_fd_recv) - { - // Both file descriptors are the same, only close one - status = Close (m_fd_send, error_ptr); - m_fd_recv = -1; - } - else + if (m_fd_send >= 0 || m_fd_recv >= 0) { - // File descriptors are the different, close both if needed - if (m_fd_send >= 0) + if (m_fd_send == m_fd_recv) + { + // Both file descriptors are the same, only close one + m_fd_recv = -1; status = Close (m_fd_send, error_ptr); - if (m_fd_recv >= 0) + } + else { - ConnectionStatus recv_status = Close (m_fd_recv, error_ptr); - if (status == eConnectionStatusSuccess) - status = recv_status; + // File descriptors are the different, close both if needed + if (m_fd_send >= 0) + status = Close (m_fd_send, error_ptr); + if (m_fd_recv >= 0) + { + ConnectionStatus recv_status = Close (m_fd_recv, error_ptr); + if (status == eConnectionStatusSuccess) + status = recv_status; + } } } return status; @@ -598,30 +603,60 @@ return eConnectionStatusLostConnection; } +//class ScopedPThreadCancelDisabler +//{ +//public: +// ScopedPThreadCancelDisabler() +// { +// // Disable the ability for this thread to be cancelled +// int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state); +// if (err != 0) +// m_old_state = -1; +// +// } +// +// ~ScopedPThreadCancelDisabler() +// { +// // Restore the ability for this thread to be cancelled to what it +// // previously was. +// if (m_old_state != -1) +// ::pthread_setcancelstate (m_old_state, 0); +// } +//private: +// int m_old_state; // Save the old cancelability state. +//}; +// ConnectionStatus ConnectionFileDescriptor::Close (int& fd, Error *error_ptr) { - //Mutex::Locker locker (m_mutex); + //ScopedPThreadCancelDisabler pthread_cancel_disabler; if (error_ptr) error_ptr->Clear(); bool success = true; + // Avoid taking a lock if we can if (fd >= 0) { - LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); - if (log) - log->Printf ("%p ConnectionFileDescriptor::Close (fd = %i)", this,fd); - - success = ::close (fd) == 0; - if (!success && error_ptr) - { - // Only set the error if we have been asked to since something else - // might have caused us to try and shut down the connection and may - // have already set the error. - error_ptr->SetErrorToErrno(); + Mutex::Locker locker (m_mutex); + // Check the FD after the lock is taken to ensure only one thread + // can get into the close scope below + if (fd >= 0) + { + LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); + if (log) + log->Printf ("%p ConnectionFileDescriptor::Close (fd = %i)", this,fd); + + success = ::close (fd) == 0; + // A reference to a FD was passed in, set it to an invalid value + fd = -1; + if (!success && error_ptr) + { + // Only set the error if we have been asked to since something else + // might have caused us to try and shut down the connection and may + // have already set the error. + error_ptr->SetErrorToErrno(); + } } - fd = -1; } - m_fd_send_type = m_fd_recv_type = eFDTypeFile; if (success) return eConnectionStatusSuccess; else Modified: lldb/tags/lldb-109/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original) +++ lldb/tags/lldb-109/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Mon Jan 30 22:35:00 2012 @@ -469,8 +469,7 @@ // Sleep for one second to let the process get all detached... StopAsyncThread (); - m_comm.StopReadThread(); - m_comm.Disconnect(); // Disconnect from the debug server. + m_comm.Clear(); SetPrivateState (eStateDetached); ResumePrivateStateThread(); @@ -508,8 +507,7 @@ } } StopAsyncThread (); - m_comm.StopReadThread(); - m_comm.Disconnect(); // Disconnect from the debug server. + m_comm.Clear(); return error; } Modified: lldb/tags/lldb-109/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/source/Target/Process.cpp?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/source/Target/Process.cpp (original) +++ lldb/tags/lldb-109/source/Target/Process.cpp Mon Jan 30 22:35:00 2012 @@ -848,7 +848,7 @@ m_abi_sp.reset(); m_os_ap.reset(); m_dyld_ap.reset(); - m_thread_list.Clear(); + m_thread_list.Destroy(); std::vector empty_notifications; m_notifications.swap(empty_notifications); m_image_tokens.clear(); @@ -2794,8 +2794,7 @@ DidDestroy(); StopPrivateStateThread(); } - m_stdio_communication.StopReadThread(); - m_stdio_communication.Disconnect(); + m_stdio_communication.Clear(); if (m_process_input_reader && m_process_input_reader->IsActive()) m_target.GetDebugger().PopInputReader (m_process_input_reader); if (m_process_input_reader) Modified: lldb/tags/lldb-109/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/source/Target/ThreadList.cpp?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/source/Target/ThreadList.cpp (original) +++ lldb/tags/lldb-109/source/Target/ThreadList.cpp Mon Jan 30 22:35:00 2012 @@ -355,6 +355,17 @@ } void +ThreadList::Destroy() +{ + Mutex::Locker locker(m_threads_mutex); + const uint32_t num_threads = m_threads.size(); + for (uint32_t idx = 0; idx < num_threads; ++idx) + { + m_threads[idx]->DestroyThread(); + } +} + +void ThreadList::RefreshStateAfterStop () { Mutex::Locker locker(m_threads_mutex); @@ -603,6 +614,32 @@ m_stop_id = rhs.m_stop_id; m_threads.swap(rhs.m_threads); m_selected_tid = rhs.m_selected_tid; + + + // Now we look for threads that we are done with and + // make sure to clear them up as much as possible so + // anyone with a shared pointer will still have a reference, + // but the thread won't be of much use. Using std::weak_ptr + // for all backward references (such as a thread to a process) + // will eventually solve this issue for us, but for now, we + // need to work around the issue + collection::iterator rhs_pos, rhs_end = rhs.m_threads.end(); + for (rhs_pos = rhs.m_threads.begin(); rhs_pos != rhs_end; ++rhs_pos) + { + const lldb::tid_t tid = (*rhs_pos)->GetID(); + bool thread_is_alive = false; + const uint32_t num_threads = m_threads.size(); + for (uint32_t idx = 0; idx < num_threads; ++idx) + { + if (m_threads[idx]->GetID() == tid) + { + thread_is_alive = true; + break; + } + } + if (!thread_is_alive) + (*rhs_pos)->DestroyThread(); + } } } Modified: lldb/tags/lldb-109/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/tools/driver/Driver.cpp?rev=149346&r1=149345&r2=149346&view=diff ============================================================================== --- lldb/tags/lldb-109/tools/driver/Driver.cpp (original) +++ lldb/tags/lldb-109/tools/driver/Driver.cpp Mon Jan 30 22:35:00 2012 @@ -1347,7 +1347,13 @@ else if (event.BroadcasterMatchesRef (sb_interpreter.GetBroadcaster())) { if (event_type & SBCommandInterpreter::eBroadcastBitQuitCommandReceived) + { + editline_output_pty.CloseMasterFileDescriptor(); + master_out_comm.Disconnect(); + out_comm_2.Disconnect(); + fclose (stdin); done = true; + } else if (event_type & SBCommandInterpreter::eBroadcastBitAsynchronousErrorData) { const char *data = SBEvent::GetCStringFromEvent (event); From gclayton at apple.com Mon Jan 30 22:39:52 2012 From: gclayton at apple.com (Greg Clayton) Date: Tue, 31 Jan 2012 04:39:52 -0000 Subject: [Lldb-commits] [lldb] r149349 - in /lldb/tags/lldb-109: lldb.xcodeproj/project.pbxproj resources/LLDB-Info.plist tools/debugserver/debugserver.xcodeproj/project.pbxproj Message-ID: <20120131043952.B4EDC2A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 22:39:52 2012 New Revision: 149349 URL: http://llvm.org/viewvc/llvm-project?rev=149349&view=rev Log: Bumping Xcode project versions for lldb-110 and debugserver-168. Modified: lldb/tags/lldb-109/lldb.xcodeproj/project.pbxproj lldb/tags/lldb-109/resources/LLDB-Info.plist lldb/tags/lldb-109/tools/debugserver/debugserver.xcodeproj/project.pbxproj Modified: lldb/tags/lldb-109/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/lldb.xcodeproj/project.pbxproj?rev=149349&r1=149348&r2=149349&view=diff ============================================================================== --- lldb/tags/lldb-109/lldb.xcodeproj/project.pbxproj (original) +++ lldb/tags/lldb-109/lldb.xcodeproj/project.pbxproj Mon Jan 30 22:39:52 2012 @@ -3733,9 +3733,9 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CURRENT_PROJECT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 109; + DYLIB_CURRENT_VERSION = 110; EXPORTED_SYMBOLS_FILE = "resources/lldb-framework-exports"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3793,10 +3793,10 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CURRENT_PROJECT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; DEAD_CODE_STRIPPING = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 109; + DYLIB_CURRENT_VERSION = 110; EXPORTED_SYMBOLS_FILE = "resources/lldb-framework-exports"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3852,8 +3852,8 @@ 2689FFD513353D7A00698AC0 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 109; - DYLIB_CURRENT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; + DYLIB_CURRENT_VERSION = 110; EXECUTABLE_EXTENSION = a; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3881,8 +3881,8 @@ 2689FFD613353D7A00698AC0 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 109; - DYLIB_CURRENT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; + DYLIB_CURRENT_VERSION = 110; EXECUTABLE_EXTENSION = a; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3910,8 +3910,8 @@ 2689FFD713353D7A00698AC0 /* BuildAndIntegration */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 109; - DYLIB_CURRENT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; + DYLIB_CURRENT_VERSION = 110; EXECUTABLE_EXTENSION = a; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3991,7 +3991,7 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"", @@ -4022,10 +4022,10 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; DEAD_CODE_STRIPPING = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 109; + DYLIB_CURRENT_VERSION = 110; EXPORTED_SYMBOLS_FILE = "resources/lldb-framework-exports"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4263,7 +4263,7 @@ 26F5C26C10F3D9A5009D5894 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"", @@ -4293,7 +4293,7 @@ 26F5C26D10F3D9A5009D5894 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 109; + CURRENT_PROJECT_VERSION = 110; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"", Modified: lldb/tags/lldb-109/resources/LLDB-Info.plist URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/resources/LLDB-Info.plist?rev=149349&r1=149348&r2=149349&view=diff ============================================================================== --- lldb/tags/lldb-109/resources/LLDB-Info.plist (original) +++ lldb/tags/lldb-109/resources/LLDB-Info.plist Mon Jan 30 22:39:52 2012 @@ -17,7 +17,7 @@ CFBundleSignature ???? CFBundleVersion - 109 + 110 CFBundleName ${EXECUTABLE_NAME} Modified: lldb/tags/lldb-109/tools/debugserver/debugserver.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-109/tools/debugserver/debugserver.xcodeproj/project.pbxproj?rev=149349&r1=149348&r2=149349&view=diff ============================================================================== --- lldb/tags/lldb-109/tools/debugserver/debugserver.xcodeproj/project.pbxproj (original) +++ lldb/tags/lldb-109/tools/debugserver/debugserver.xcodeproj/project.pbxproj Mon Jan 30 22:39:52 2012 @@ -475,7 +475,7 @@ i386, ); COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 167; + CURRENT_PROJECT_VERSION = 168; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; SDKROOT = ""; @@ -494,7 +494,7 @@ x86_64, i386, ); - CURRENT_PROJECT_VERSION = 167; + CURRENT_PROJECT_VERSION = 168; DEAD_CODE_STRIPPING = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -515,7 +515,7 @@ x86_64, i386, ); - CURRENT_PROJECT_VERSION = 167; + CURRENT_PROJECT_VERSION = 168; DEAD_CODE_STRIPPING = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -534,7 +534,7 @@ "ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist"; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 167; + CURRENT_PROJECT_VERSION = 168; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks; "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = ( @@ -574,7 +574,7 @@ "ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist"; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 167; + CURRENT_PROJECT_VERSION = 168; FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks; "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = ( "$(SDKROOT)/System/Library/PrivateFrameworks", @@ -613,7 +613,7 @@ "ARCHS[sdk=iphoneos*]" = "$(ARCHS_STANDARD_32_BIT)"; "CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist"; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 167; + CURRENT_PROJECT_VERSION = 168; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks; "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = ( From gclayton at apple.com Mon Jan 30 22:40:14 2012 From: gclayton at apple.com (Greg Clayton) Date: Tue, 31 Jan 2012 04:40:14 -0000 Subject: [Lldb-commits] [lldb] r149350 - /lldb/tags/lldb-110/ Message-ID: <20120131044014.44ED92A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 22:40:14 2012 New Revision: 149350 URL: http://llvm.org/viewvc/llvm-project?rev=149350&view=rev Log: lldb-110 Added: lldb/tags/lldb-110/ - copied from r149349, lldb/tags/lldb-109/ From gclayton at apple.com Mon Jan 30 22:56:17 2012 From: gclayton at apple.com (Greg Clayton) Date: Tue, 31 Jan 2012 04:56:17 -0000 Subject: [Lldb-commits] [lldb] r149355 - in /lldb/trunk: include/lldb/Core/ConnectionFileDescriptor.h source/Core/Communication.cpp source/Core/ConnectionFileDescriptor.cpp source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp tools/driver/Driver.cpp Message-ID: <20120131045617.77ECB2A6C12C@llvm.org> Author: gclayton Date: Mon Jan 30 22:56:17 2012 New Revision: 149355 URL: http://llvm.org/viewvc/llvm-project?rev=149355&view=rev Log: Cleaned up the Communication class when it tears down ConnectionFileDescriptor instances to not pthread_cancel the read threads and wreak havoc on the mutex in our ConnectionFileDescriptor class. Also cleaned up some shutdown delays. Modified: lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h lldb/trunk/source/Core/Communication.cpp lldb/trunk/source/Core/ConnectionFileDescriptor.cpp lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp lldb/trunk/tools/driver/Driver.cpp Modified: lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h?rev=149355&r1=149354&r2=149355&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h (original) +++ lldb/trunk/include/lldb/Core/ConnectionFileDescriptor.h Mon Jan 30 22:56:17 2012 @@ -105,7 +105,7 @@ SocketAddress m_udp_send_sockaddr; bool m_should_close_fd; // True if this class should close the file descriptor when it goes away. uint32_t m_socket_timeout_usec; - //Mutex m_mutex; + Mutex m_mutex; static in_port_t GetSocketPort (int fd); Modified: lldb/trunk/source/Core/Communication.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Communication.cpp?rev=149355&r1=149354&r2=149355&view=diff ============================================================================== --- lldb/trunk/source/Core/Communication.cpp (original) +++ lldb/trunk/source/Core/Communication.cpp Mon Jan 30 22:56:17 2012 @@ -65,8 +65,8 @@ Communication::Clear() { SetReadThreadBytesReceivedCallback (NULL, NULL); - StopReadThread (NULL); Disconnect (NULL); + StopReadThread (NULL); } ConnectionStatus @@ -253,7 +253,7 @@ BroadcastEvent (eBroadcastBitReadThreadShouldExit, NULL); - Host::ThreadCancel (m_read_thread, error_ptr); + //Host::ThreadCancel (m_read_thread, error_ptr); bool status = Host::ThreadJoin (m_read_thread, NULL, error_ptr); m_read_thread = LLDB_INVALID_HOST_THREAD; @@ -383,7 +383,7 @@ // Let clients know that this thread is exiting comm->BroadcastEvent (eBroadcastBitReadThreadDidExit); comm->m_read_thread_enabled = false; - comm->Disconnect(); + comm->m_read_thread = LLDB_INVALID_HOST_THREAD; return NULL; } @@ -401,8 +401,8 @@ void Communication::SetConnection (Connection *connection) { - StopReadThread(NULL); Disconnect (NULL); + StopReadThread(NULL); m_connection_sp.reset(connection); } Modified: lldb/trunk/source/Core/ConnectionFileDescriptor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConnectionFileDescriptor.cpp?rev=149355&r1=149354&r2=149355&view=diff ============================================================================== --- lldb/trunk/source/Core/ConnectionFileDescriptor.cpp (original) +++ lldb/trunk/source/Core/ConnectionFileDescriptor.cpp Mon Jan 30 22:56:17 2012 @@ -73,8 +73,8 @@ m_fd_recv_type (eFDTypeFile), m_udp_send_sockaddr (), m_should_close_fd (false), - m_socket_timeout_usec(0)//, - //m_mutex (Mutex::eMutexTypeRecursive) + m_socket_timeout_usec(0), + m_mutex (Mutex::eMutexTypeRecursive) { LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) @@ -89,7 +89,8 @@ m_fd_recv_type (eFDTypeFile), m_udp_send_sockaddr (), m_should_close_fd (owns_fd), - m_socket_timeout_usec(0) + m_socket_timeout_usec(0), + m_mutex (Mutex::eMutexTypeRecursive) { LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION | LIBLLDB_LOG_OBJECT)); if (log) @@ -114,7 +115,7 @@ ConnectionStatus ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr) { - //Mutex::Locker locker (m_mutex); + Mutex::Locker locker (m_mutex); LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); if (log) log->Printf ("%p ConnectionFileDescriptor::Connect (url = '%s')", this, s); @@ -234,6 +235,7 @@ ConnectionStatus ConnectionFileDescriptor::Disconnect (Error *error_ptr) { + Mutex::Locker locker (m_mutex); LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); if (log) log->Printf ("%p ConnectionFileDescriptor::Disconnect ()", this); @@ -243,22 +245,25 @@ return eConnectionStatusSuccess; } ConnectionStatus status = eConnectionStatusSuccess; - if (m_fd_send == m_fd_recv) + if (m_fd_send >= 0 || m_fd_recv >= 0) { - // Both file descriptors are the same, only close one - status = Close (m_fd_send, error_ptr); - m_fd_recv = -1; - } - else - { - // File descriptors are the different, close both if needed - if (m_fd_send >= 0) + if (m_fd_send == m_fd_recv) + { + // Both file descriptors are the same, only close one + m_fd_recv = -1; status = Close (m_fd_send, error_ptr); - if (m_fd_recv >= 0) + } + else { - ConnectionStatus recv_status = Close (m_fd_recv, error_ptr); - if (status == eConnectionStatusSuccess) - status = recv_status; + // File descriptors are the different, close both if needed + if (m_fd_send >= 0) + status = Close (m_fd_send, error_ptr); + if (m_fd_recv >= 0) + { + ConnectionStatus recv_status = Close (m_fd_recv, error_ptr); + if (status == eConnectionStatusSuccess) + status = recv_status; + } } } return status; @@ -601,27 +606,33 @@ ConnectionStatus ConnectionFileDescriptor::Close (int& fd, Error *error_ptr) { - //Mutex::Locker locker (m_mutex); if (error_ptr) error_ptr->Clear(); bool success = true; + // Avoid taking a lock if we can if (fd >= 0) { - LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); - if (log) - log->Printf ("%p ConnectionFileDescriptor::Close (fd = %i)", this,fd); - - success = ::close (fd) == 0; - if (!success && error_ptr) - { - // Only set the error if we have been asked to since something else - // might have caused us to try and shut down the connection and may - // have already set the error. - error_ptr->SetErrorToErrno(); + Mutex::Locker locker (m_mutex); + // Check the FD after the lock is taken to ensure only one thread + // can get into the close scope below + if (fd >= 0) + { + LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); + if (log) + log->Printf ("%p ConnectionFileDescriptor::Close (fd = %i)", this,fd); + + success = ::close (fd) == 0; + // A reference to a FD was passed in, set it to an invalid value + fd = -1; + if (!success && error_ptr) + { + // Only set the error if we have been asked to since something else + // might have caused us to try and shut down the connection and may + // have already set the error. + error_ptr->SetErrorToErrno(); + } } - fd = -1; } - m_fd_send_type = m_fd_recv_type = eFDTypeFile; if (success) return eConnectionStatusSuccess; else Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp?rev=149355&r1=149354&r2=149355&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp Mon Jan 30 22:56:17 2012 @@ -469,8 +469,7 @@ // Sleep for one second to let the process get all detached... StopAsyncThread (); - m_comm.StopReadThread(); - m_comm.Disconnect(); // Disconnect from the debug server. + m_comm.Clear(); SetPrivateState (eStateDetached); ResumePrivateStateThread(); @@ -508,8 +507,7 @@ } } StopAsyncThread (); - m_comm.StopReadThread(); - m_comm.Disconnect(); // Disconnect from the debug server. + m_comm.Clear(); return error; } Modified: lldb/trunk/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=149355&r1=149354&r2=149355&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.cpp (original) +++ lldb/trunk/tools/driver/Driver.cpp Mon Jan 30 22:56:17 2012 @@ -1347,7 +1347,13 @@ else if (event.BroadcasterMatchesRef (sb_interpreter.GetBroadcaster())) { if (event_type & SBCommandInterpreter::eBroadcastBitQuitCommandReceived) + { + editline_output_pty.CloseMasterFileDescriptor(); + master_out_comm.Disconnect(); + out_comm_2.Disconnect(); + fclose (stdin); done = true; + } else if (event_type & SBCommandInterpreter::eBroadcastBitAsynchronousErrorData) { const char *data = SBEvent::GetCStringFromEvent (event); From granata.enrico at gmail.com Tue Jan 31 11:01:52 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Tue, 31 Jan 2012 17:01:52 -0000 Subject: [Lldb-commits] [lldb] r149388 - in /lldb/trunk: examples/summaries/objc.py include/lldb/Core/FormatManager.h scripts/Python/finish-swig-Python-LLDB.sh source/Core/FormatManager.cpp source/Interpreter/ScriptInterpreterPython.cpp Message-ID: <20120131170152.31BAE2A6C12C@llvm.org> Author: enrico Date: Tue Jan 31 11:01:51 2012 New Revision: 149388 URL: http://llvm.org/viewvc/llvm-project?rev=149388&view=rev Log: This commit provides a new default summary for Objective-C boolean variables, which shows YES or NO instead of the character value. A new category named objc is added to contain this summary provider. Any future Objective-C related formatters would probably fit here Added: lldb/trunk/examples/summaries/objc.py Modified: lldb/trunk/include/lldb/Core/FormatManager.h lldb/trunk/scripts/Python/finish-swig-Python-LLDB.sh lldb/trunk/source/Core/FormatManager.cpp lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Added: lldb/trunk/examples/summaries/objc.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/objc.py?rev=149388&view=auto ============================================================================== --- lldb/trunk/examples/summaries/objc.py (added) +++ lldb/trunk/examples/summaries/objc.py Tue Jan 31 11:01:51 2012 @@ -0,0 +1,9 @@ +# Summaries for common ObjC types that require Python scripting +# to be generated fit into this file + +def BOOL_SummaryProvider (valobj,dict): + if valobj.GetValueAsUnsigned() == 0: + return "NO" + else: + return "YES" + Modified: lldb/trunk/include/lldb/Core/FormatManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=149388&r1=149387&r2=149388&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FormatManager.h (original) +++ lldb/trunk/include/lldb/Core/FormatManager.h Tue Jan 31 11:01:51 2012 @@ -508,6 +508,7 @@ ConstString m_default_category_name; ConstString m_system_category_name; ConstString m_gnu_cpp_category_name; + ConstString m_objc_category_name; CategoryMap& GetCategories () Modified: lldb/trunk/scripts/Python/finish-swig-Python-LLDB.sh URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/finish-swig-Python-LLDB.sh?rev=149388&r1=149387&r2=149388&view=diff ============================================================================== --- lldb/trunk/scripts/Python/finish-swig-Python-LLDB.sh (original) +++ lldb/trunk/scripts/Python/finish-swig-Python-LLDB.sh Tue Jan 31 11:01:51 2012 @@ -184,6 +184,21 @@ fi fi +# Copy the ObjC formatters over to the framework Python directory +if [ -f "${SRC_ROOT}/examples/synthetic/objc.py" ] +then + if [ $Debug == 1 ] + then + echo "Copying objc.py to ${framework_python_dir}" + fi + cp "${SRC_ROOT}/examples/summaries/objc.py" "${framework_python_dir}" +else + if [ $Debug == 1 ] + then + echo "Unable to find ${SRC_ROOT}/examples/summaries/objc.py" + fi +fi + fi exit 0 Modified: lldb/trunk/source/Core/FormatManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=149388&r1=149387&r2=149388&view=diff ============================================================================== --- lldb/trunk/source/Core/FormatManager.cpp (original) +++ lldb/trunk/source/Core/FormatManager.cpp Tue Jan 31 11:01:51 2012 @@ -560,7 +560,8 @@ m_categories_map(this), m_default_category_name(ConstString("default")), m_system_category_name(ConstString("system")), - m_gnu_cpp_category_name(ConstString("gnu-libstdc++")) + m_gnu_cpp_category_name(ConstString("gnu-libstdc++")), + m_objc_category_name(ConstString("objc")) { // add some default stuff @@ -584,7 +585,6 @@ lldb::RegularExpressionSP any_size_char_arr(new RegularExpression("char \\[[0-9]+\\]")); - FormatCategory::SharedPointer sys_category_sp = GetCategory(m_system_category_name); sys_category_sp->GetSummaryNavigator()->Add(ConstString("char *"), string_format); @@ -633,9 +633,23 @@ false, false, "gnu_libstdcpp.StdListSynthProvider"))); + + lldb::SummaryFormatSP ObjC_BOOL_summary(new ScriptSummaryFormat(false, + false, + false, + true, + true, + false, + "objc.BOOL_SummaryProvider", + "")); + FormatCategory::SharedPointer objc_category_sp = GetCategory(m_objc_category_name); + objc_category_sp->GetSummaryNavigator()->Add(ConstString("BOOL"), + ObjC_BOOL_summary); #endif + // DO NOT change the order of these calls, unless you WANT a change in the priority of these categories EnableCategory(m_system_category_name); + EnableCategory(m_objc_category_name); EnableCategory(m_gnu_cpp_category_name); EnableCategory(m_default_category_name); Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=149388&r1=149387&r2=149388&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Tue Jan 31 11:01:51 2012 @@ -247,6 +247,10 @@ run_string.Printf ("run_one_line (%s, 'import gnu_libstdcpp')", m_dictionary_name.c_str()); PyRun_SimpleString (run_string.GetData()); + run_string.Clear(); + run_string.Printf ("run_one_line (%s, 'import objc')", m_dictionary_name.c_str()); + PyRun_SimpleString (run_string.GetData()); + if (m_dbg_stdout != NULL) { m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush); From granata.enrico at gmail.com Tue Jan 31 11:18:41 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Tue, 31 Jan 2012 17:18:41 -0000 Subject: [Lldb-commits] [lldb] r149390 - in /lldb/trunk: include/lldb/Core/Stream.h source/Core/Stream.cpp Message-ID: <20120131171841.3E38E2A6C12C@llvm.org> Author: enrico Date: Tue Jan 31 11:18:40 2012 New Revision: 149390 URL: http://llvm.org/viewvc/llvm-project?rev=149390&view=rev Log: Comments edited to better reflect what the function really does Modified: lldb/trunk/include/lldb/Core/Stream.h lldb/trunk/source/Core/Stream.cpp Modified: lldb/trunk/include/lldb/Core/Stream.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Stream.h?rev=149390&r1=149389&r2=149390&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Stream.h (original) +++ lldb/trunk/include/lldb/Core/Stream.h Tue Jan 31 11:18:40 2012 @@ -383,13 +383,12 @@ AddressRange(uint64_t lo_addr, uint64_t hi_addr, int addr_size, const char *prefix = NULL, const char *suffix = NULL); //------------------------------------------------------------------ - /// Output a C string to the stream with optional format. + /// Output a C string to the stream. /// - /// Print a C string \a cstr to the stream using the printf format - /// in \a format. + /// Print a C string \a cstr to the stream. /// - /// @param[in] format - /// The printf style format to use when outputting the C string. + /// @param[in] cstr + /// The string to be output to the stream. //------------------------------------------------------------------ int PutCString (const char *cstr); Modified: lldb/trunk/source/Core/Stream.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Stream.cpp?rev=149390&r1=149389&r2=149390&view=diff ============================================================================== --- lldb/trunk/source/Core/Stream.cpp (original) +++ lldb/trunk/source/Core/Stream.cpp Tue Jan 31 11:18:40 2012 @@ -122,8 +122,7 @@ } //------------------------------------------------------------------ -// Print a raw NULL terminated C string to the stream using the -// printf format in "format". +// Print a raw NULL terminated C string to the stream. //------------------------------------------------------------------ int Stream::PutCString (const char *cstr) From granata.enrico at gmail.com Tue Jan 31 11:50:00 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Tue, 31 Jan 2012 17:50:00 -0000 Subject: [Lldb-commits] [lldb] r149393 - in /lldb/trunk/test/functionalities/data-formatter: data-formatter-python-synth/StdListSynthProvider.py data-formatter-python-synth/StdMapSynthProvider.py data-formatter-python-synth/StdVectorSynthProvider.py data-formatter-python-synth/TestDataFormatterPythonSynth.py data-formatter-python-synth/main.cpp data-formatter-stl/ data-formatter-stl/list/ data-formatter-stl/map/ data-formatter-stl/vector/ Message-ID: <20120131175001.0FD162A6C12C@llvm.org> Author: enrico Date: Tue Jan 31 11:50:00 2012 New Revision: 149393 URL: http://llvm.org/viewvc/llvm-project?rev=149393&view=rev Log: Splitting test case for Python synthetic children: part 1 test is only testing the synthetic children feature itself. More test cases will be commited for individual STL containers Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/ Removed: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdListSynthProvider.py lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdMapSynthProvider.py lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp Removed: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdListSynthProvider.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdListSynthProvider.py?rev=149392&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdListSynthProvider.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdListSynthProvider.py (removed) @@ -1,64 +0,0 @@ -import re -class StdListSynthProvider: - - def __init__(self, valobj, dict): - self.valobj = valobj - self.update() - - def num_children(self): - next_val = self.next.GetValueAsUnsigned(0) - prev_val = self.prev.GetValueAsUnsigned(0) - # After a std::list has been initialized, both next and prev will be non-NULL - if next_val == 0 or prev_val == 0: - return 0 - if next_val == self.node_address: - return 0 - if next_val == prev_val: - return 1 - size = 2 - current = self.next - while current.GetChildMemberWithName('_M_next').GetValueAsUnsigned(0) != self.node_address: - size = size + 1 - current = current.GetChildMemberWithName('_M_next') - return (size - 1) - - def get_child_index(self,name): - return int(name.lstrip('[').rstrip(']')) - - def get_child_at_index(self,index): - if index >= self.num_children(): - return None; - offset = index - current = self.next - while offset > 0: - current = current.GetChildMemberWithName('_M_next') - offset = offset - 1 - return current.CreateChildAtOffset('['+str(index)+']',2*current.GetType().GetByteSize(),self.data_type) - - def extract_type_name(self,name): - self.type_name = name[16:] - index = 2 - count_of_template = 1 - while index < len(self.type_name): - if self.type_name[index] == '<': - count_of_template = count_of_template + 1 - elif self.type_name[index] == '>': - count_of_template = count_of_template - 1 - elif self.type_name[index] == ',' and count_of_template == 1: - self.type_name = self.type_name[:index] - break - index = index + 1 - self.type_name_nospaces = self.type_name.replace(", ", ",") - - def update(self): - impl = self.valobj.GetChildMemberWithName('_M_impl') - node = impl.GetChildMemberWithName('_M_node') - self.extract_type_name(impl.GetType().GetName()) - self.node_address = self.valobj.AddressOf().GetValueAsUnsigned(0) - self.next = node.GetChildMemberWithName('_M_next') - self.prev = node.GetChildMemberWithName('_M_prev') - self.data_type = node.GetTarget().FindFirstType(self.type_name) - # tries to fight against a difference in formatting type names between gcc and clang - if self.data_type.IsValid() == False: - self.data_type = node.GetTarget().FindFirstType(self.type_name_nospaces) - self.data_size = self.data_type.GetByteSize() Removed: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdMapSynthProvider.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdMapSynthProvider.py?rev=149392&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdMapSynthProvider.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdMapSynthProvider.py (removed) @@ -1,112 +0,0 @@ -import re - -class StdMapSynthProvider: - - def __init__(self, valobj, dict): - self.valobj = valobj; - self.update() - - def update(self): - self.Mt = self.valobj.GetChildMemberWithName('_M_t') - self.Mimpl = self.Mt.GetChildMemberWithName('_M_impl') - self.Mheader = self.Mimpl.GetChildMemberWithName('_M_header') - # from libstdc++ implementation of _M_root for rbtree - self.Mroot = self.Mheader.GetChildMemberWithName('_M_parent') - # the stuff into the tree is actually a std::pair - # life would be much easier if gcc had a coherent way to print out - # template names in debug info - self.expand_clang_type_name() - self.expand_gcc_type_name() - self.data_type = self.Mt.GetTarget().FindFirstType(self.clang_type_name) - if self.data_type.IsValid() == False: - self.data_type = self.Mt.GetTarget().FindFirstType(self.gcc_type_name) - self.data_size = self.data_type.GetByteSize() - self.skip_size = self.Mheader.GetType().GetByteSize() - - def expand_clang_type_name(self): - type_name = self.Mimpl.GetType().GetName() - index = type_name.find("std::pair<") - type_name = type_name[index+5:] - index = 6 - template_count = 1 - while index < len(type_name): - if type_name[index] == '<': - template_count = template_count + 1 - elif type_name[index] == '>' and template_count == 1: - type_name = type_name[:index+1] - break - elif type_name[index] == '>': - template_count = template_count - 1 - index = index + 1; - self.clang_type_name = type_name - - def expand_gcc_type_name(self): - type_name = self.Mt.GetType().GetName() - index = type_name.find("std::pair<") - type_name = type_name[index+5:] - index = 6 - template_count = 1 - while index < len(type_name): - if type_name[index] == '<': - template_count = template_count + 1 - elif type_name[index] == '>' and template_count == 1: - type_name = type_name[:index+1] - break - elif type_name[index] == '>': - template_count = template_count - 1 - elif type_name[index] == ' ' and template_count == 1 and type_name[index-1] == ',': - type_name = type_name[0:index] + type_name[index+1:] - index = index - 1 - index = index + 1; - self.gcc_type_name = type_name - - def num_children(self): - root_ptr_val = self.node_ptr_value(self.Mroot) - if root_ptr_val == 0: - return 0; - return self.Mimpl.GetChildMemberWithName('_M_node_count').GetValueAsUnsigned(0) - - def get_child_index(self,name): - return int(name.lstrip('[').rstrip(']')) - - def get_child_at_index(self,index): - if index >= self.num_children(): - return None; - offset = index - current = self.left(self.Mheader); - while offset > 0: - current = self.increment_node(current) - offset = offset - 1; - # skip all the base stuff and get at the data - return current.CreateChildAtOffset('['+str(index)+']',self.skip_size,self.data_type) - - # utility functions - def node_ptr_value(self,node): - return node.GetValueAsUnsigned(0) - - def right(self,node): - return node.GetChildMemberWithName("_M_right"); - - def left(self,node): - return node.GetChildMemberWithName("_M_left"); - - def parent(self,node): - return node.GetChildMemberWithName("_M_parent"); - - # from libstdc++ implementation of iterator for rbtree - def increment_node(self,node): - if self.node_ptr_value(self.right(node)) != 0: - x = self.right(node); - while self.node_ptr_value(self.left(x)) != 0: - x = self.left(x); - return x; - else: - x = node; - y = self.parent(x) - while(self.node_ptr_value(x) == self.node_ptr_value(self.right(y))): - x = y; - y = self.parent(y); - if self.node_ptr_value(self.right(x)) != self.node_ptr_value(y): - x = y; - return x; - Removed: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py?rev=149392&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/StdVectorSynthProvider.py (removed) @@ -1,52 +0,0 @@ -class StdVectorSynthProvider: - - def __init__(self, valobj, dict): - self.valobj = valobj; - self.update() - - def num_children(self): - start_val = self.start.GetValueAsUnsigned(0) - finish_val = self.finish.GetValueAsUnsigned(0) - end_val = self.end.GetValueAsUnsigned(0) - # Before a vector has been constructed, it will contain bad values - # so we really need to be careful about the length we return since - # unitialized data can cause us to return a huge number. We need - # to also check for any of the start, finish or end of storage values - # being zero (NULL). If any are, then this vector has not been - # initialized yet and we should return zero - - # Make sure nothing is NULL - if start_val == 0 or finish_val == 0 or end_val == 0: - return 0 - # Make sure start is less than finish - if start_val >= finish_val: - return 0 - # Make sure finish is less than or equal to end of storage - if finish_val > end_val: - return 0 - - # We might still get things wrong, so cap things at 256 items for now - # TODO: read a target "settings set" variable for this to allow it to - # be customized - num_children = (finish_val-start_val)/self.data_size - if num_children > 256: - return 256 - return num_children - - def get_child_index(self,name): - return int(name.lstrip('[').rstrip(']')) - - def get_child_at_index(self,index): - if index >= self.num_children(): - return None; - offset = index * self.data_size - return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type) - - def update(self): - impl = self.valobj.GetChildMemberWithName('_M_impl') - self.start = impl.GetChildMemberWithName('_M_start') - self.finish = impl.GetChildMemberWithName('_M_finish') - self.end = impl.GetChildMemberWithName('_M_end_of_storage') - self.data_type = self.start.GetType().GetPointeeType() - self.data_size = self.data_type.GetByteSize() - Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py?rev=149393&r1=149392&r2=149393&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py Tue Jan 31 11:50:00 2012 @@ -11,16 +11,12 @@ mydir = os.path.join("functionalities", "data-formatter", "data-formatter-python-synth") - #rdar://problem/10334911 - @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_with_dsym_and_run_command(self): """Test data formatter commands.""" self.buildDsym() self.data_formatter_commands() - #rdar://problem/10334911 - @unittest2.expectedFailure def test_with_dwarf_and_run_command(self): """Test data formatter commands.""" self.buildDwarf() @@ -92,12 +88,12 @@ self.runCmd("type summary add --summary-string \"fake_a=${svar.fake_a}\" foo") self.expect('frame variable f00_1', substrs = ['fake_a=16777216']) - self.runCmd("type summary add --summary-string \"fake_a=${var.fake_a}\" foo") - self.expect('frame variable f00_1', - substrs = ['fake_a=16777216']) - self.runCmd("type summary add --summary-string \"fake_a=${var[1]}\" foo") - self.expect('frame variable f00_1', - substrs = ['fake_a=16777216']) + #self.runCmd("type summary add --summary-string \"fake_a=${var.fake_a}\" foo") + #self.expect('frame variable f00_1', + # substrs = ['fake_a=16777216']) + #self.runCmd("type summary add --summary-string \"fake_a=${var[1]}\" foo") + #self.expect('frame variable f00_1', + # substrs = ['fake_a=16777216']) self.runCmd("type summary add --summary-string \"fake_a=${svar[1]}\" foo") self.expect('frame variable f00_1', substrs = ['fake_a=16777216']) @@ -221,561 +217,6 @@ 'C', 'D']) - # now start playing with STL containers - # having std:: here is a workaround for rdar://problem/9835692 - - - # std::vector - #self.runCmd("script from StdVectorSynthProvider import *") - #self.runCmd("type synth add -l StdVectorSynthProvider std::int_vect int_vect") - #self.runCmd("type synth add -l StdVectorSynthProvider std::string_vect string_vect") - - self.runCmd("n") - - # empty vectors (and storage pointers SHOULD BOTH BE NULL..) - self.expect("frame variable numbers", - substrs = ['numbers = {}']) - - self.runCmd("n") - - # first value added - self.expect("frame variable numbers", - substrs = ['numbers = {', - '[0] = 1', - '}']) - - # add some more data - self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable numbers", - substrs = ['numbers = {', - '[0] = 1', - '[1] = 12', - '[2] = 123', - '[3] = 1234', - '}']) - - self.expect("p numbers", - substrs = ['$', '= {', - '[0] = 1', - '[1] = 12', - '[2] = 123', - '[3] = 1234', - '}']) - - - # check access to synthetic children - self.runCmd("type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect") - self.expect('frame variable numbers', - substrs = ['item 0 is 1']); - - self.runCmd("type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect") - #import time - #time.sleep(19) - self.expect('frame variable numbers', - substrs = ['item 0 is 1']); - # move on with synths - self.runCmd("type summary delete std::int_vect") - self.runCmd("type summary delete int_vect") - - # add some more data - self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable numbers", - substrs = ['numbers = {', - '[0] = 1', - '[1] = 12', - '[2] = 123', - '[3] = 1234', - '[4] = 12345', - '[5] = 123456', - '[6] = 1234567', - '}']) - - self.expect("p numbers", - substrs = ['$', ' = {', - '[0] = 1', - '[1] = 12', - '[2] = 123', - '[3] = 1234', - '[4] = 12345', - '[5] = 123456', - '[6] = 1234567', - '}']) - - # check access-by-index - self.expect("frame variable numbers[0]", - substrs = ['1']); - self.expect("frame variable numbers[1]", - substrs = ['12']); - self.expect("frame variable numbers[2]", - substrs = ['123']); - self.expect("frame variable numbers[3]", - substrs = ['1234']); - - # but check that expression does not rely on us - # (when expression gets to call into STL code correctly, we will have to find - # another way to check this) - self.expect("expression numbers[6]", matching=False, error=True, - substrs = ['1234567']) - - # clear out the vector and see that we do the right thing once again - self.runCmd("n") - - self.expect("frame variable numbers", - substrs = ['numbers = {}']) - - self.runCmd("n") - - # first value added - self.expect("frame variable numbers", - substrs = ['numbers = {', - '[0] = 7', - '}']) - - # check if we can display strings - self.runCmd("n") - self.runCmd("n") - self.runCmd("n") - self.runCmd("n") - - self.expect("frame variable strings", - substrs = ['goofy', - 'is', - 'smart']) - - self.expect("p strings", - substrs = ['goofy', - 'is', - 'smart']) - - # test summaries based on synthetic children - self.runCmd("type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e") - self.expect("frame variable strings", - substrs = ['vector has 3 items', - 'goofy', - 'is', - 'smart']) - - self.expect("p strings", - substrs = ['vector has 3 items', - 'goofy', - 'is', - 'smart']) - - self.runCmd("n"); - - self.expect("frame variable strings", - substrs = ['vector has 4 items']) - - # check access-by-index - self.expect("frame variable strings[0]", - substrs = ['goofy']); - self.expect("frame variable strings[1]", - substrs = ['is']); - - # but check that expression does not rely on us - # (when expression gets to call into STL code correctly, we will have to find - # another way to check this) - self.expect("expression strings[0]", matching=False, error=True, - substrs = ['goofy']) - - self.runCmd("n") - - self.expect("frame variable strings", - substrs = ['vector has 0 items']) - - # now test std::list - #self.runCmd("script from StdListSynthProvider import *") - - self.runCmd("n") - - self.runCmd("frame variable numbers_list -T") - #self.runCmd("type synth add std::int_list std::string_list int_list string_list -l StdListSynthProvider") - self.runCmd("type summary add std::int_list std::string_list int_list string_list --summary-string \"list has ${svar%#} items\" -e") - self.runCmd("type format add -f hex int") - - self.expect("frame variable numbers_list --raw", matching=False, - substrs = ['list has 0 items', - '{}']) - - self.expect("frame variable numbers_list", - substrs = ['list has 0 items', - '{}']) - - self.expect("p numbers_list", - substrs = ['list has 0 items', - '{}']) - - self.runCmd("n") - - self.expect("frame variable numbers_list", - substrs = ['list has 1 items', - '[0] = ', - '0x12345678']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable numbers_list", - substrs = ['list has 4 items', - '[0] = ', - '0x12345678', - '[1] =', - '0x11223344', - '[2] =', - '0xbeeffeed', - '[3] =', - '0x00abba00']) - - self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable numbers_list", - substrs = ['list has 6 items', - '[0] = ', - '0x12345678', - '0x11223344', - '0xbeeffeed', - '0x00abba00', - '[4] =', - '0x0abcdef0', - '[5] =', - '0x0cab0cab']) - - self.expect("p numbers_list", - substrs = ['list has 6 items', - '[0] = ', - '0x12345678', - '0x11223344', - '0xbeeffeed', - '0x00abba00', - '[4] =', - '0x0abcdef0', - '[5] =', - '0x0cab0cab']) - - # check access-by-index - self.expect("frame variable numbers_list[0]", - substrs = ['0x12345678']); - self.expect("frame variable numbers_list[1]", - substrs = ['0x11223344']); - - # but check that expression does not rely on us - self.expect("expression numbers_list[0]", matching=False, error=True, - substrs = ['0x12345678']) - - self.runCmd("n") - - self.expect("frame variable numbers_list", - substrs = ['list has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable numbers_list", - substrs = ['list has 4 items', - '[0] = ', '1', - '[1] = ', '2', - '[2] = ', '3', - '[3] = ', '4']) - - self.runCmd("type format delete int") - - self.runCmd("n") - - self.expect("frame variable text_list", - substrs = ['list has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable text_list", - substrs = ['list has 4 items', - '[0]', 'goofy', - '[1]', 'is', - '[2]', 'smart', - '[3]', '!!!']) - - self.expect("p text_list", - substrs = ['list has 4 items', - '[0] = \"goofy\"', - '[1] = \"is\"', - '[2] = \"smart\"', - '[3] = \"!!!\"']) - - # check access-by-index - self.expect("frame variable text_list[0]", - substrs = ['goofy']); - self.expect("frame variable text_list[3]", - substrs = ['!!!']); - - # but check that expression does not rely on us - self.expect("expression text_list[0]", matching=False, error=True, - substrs = ['goofy']) - - # now std::map - # also take a chance to test regex synth here - - self.runCmd("n") - self.runCmd("frame variable ii -T") - - #self.runCmd("script from StdMapSynthProvider import *") - self.runCmd("type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e") - - #import time - #time.sleep(30) - - #self.runCmd("type synth add -x \"std::map<\" -l StdMapSynthProvider") - - - self.expect('frame variable ii', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n"); - - self.expect('frame variable ii', - substrs = ['map has 2 items', - '[0] = {', - 'first = 0', - 'second = 0', - '[1] = {', - 'first = 1', - 'second = 1']) - - self.runCmd("n");self.runCmd("n"); - - self.expect('frame variable ii', - substrs = ['map has 4 items', - '[2] = {', - 'first = 2', - 'second = 0', - '[3] = {', - 'first = 3', - 'second = 1']) - - self.runCmd("n");self.runCmd("n"); - self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable ii", - substrs = ['map has 9 items', - '[5] = {', - 'first = 5', - 'second = 0', - '[7] = {', - 'first = 7', - 'second = 1']) - - self.expect("p ii", - substrs = ['map has 9 items', - '[5] = {', - 'first = 5', - 'second = 0', - '[7] = {', - 'first = 7', - 'second = 1']) - - # check access-by-index - self.expect("frame variable ii[0]", - substrs = ['first = 0', - 'second = 0']); - self.expect("frame variable ii[3]", - substrs = ['first =', - 'second =']); - - # but check that expression does not rely on us - self.expect("expression ii[0]", matching=False, error=True, - substrs = ['first = 0']) - - self.runCmd("n") - - self.expect('frame variable ii', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - self.runCmd("frame variable si -T") - - #self.runCmd("type summary add std::strint_map strint_map --summary-string \"map has ${svar%#} items\" -e") - #self.runCmd("type synth add std::strint_map strint_map -l StdMapSynthProvider") - - self.expect('frame variable si', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - - self.expect('frame variable si', - substrs = ['map has 1 items', - '[0] = ', - 'first = \"zero\"', - 'second = 0']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable si", - substrs = ['map has 5 items', - '[0] = ', - 'first = \"zero\"', - 'second = 0', - '[1] = ', - 'first = \"one\"', - 'second = 1', - '[2] = ', - 'first = \"two\"', - 'second = 2', - '[3] = ', - 'first = \"three\"', - 'second = 3', - '[4] = ', - 'first = \"four\"', - 'second = 4']) - - self.expect("p si", - substrs = ['map has 5 items', - '[0] = ', - 'first = \"zero\"', - 'second = 0', - '[1] = ', - 'first = \"one\"', - 'second = 1', - '[2] = ', - 'first = \"two\"', - 'second = 2', - '[3] = ', - 'first = \"three\"', - 'second = 3', - '[4] = ', - 'first = \"four\"', - 'second = 4']) - - # check access-by-index - self.expect("frame variable si[0]", - substrs = ['first = ', 'four', - 'second = 4']); - - # but check that expression does not rely on us - self.expect("expression si[0]", matching=False, error=True, - substrs = ['first = ', 'zero']) - - self.runCmd("n") - - self.expect('frame variable si', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - self.runCmd("frame variable is -T") - - #self.runCmd("type summary add std::intstr_map intstr_map --summary-string \"map has ${svar%#} items\" -e") - #self.runCmd("type synth add std::intstr_map intstr_map -l StdMapSynthProvider") - - self.expect('frame variable is', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable is", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"goofy\"', - 'first = 0', - '[1] = ', - 'second = \"is\"', - 'first = 1', - '[2] = ', - 'second = \"smart\"', - 'first = 2', - '[3] = ', - 'second = \"!!!\"', - 'first = 3']) - - self.expect("p is", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"goofy\"', - 'first = 0', - '[1] = ', - 'second = \"is\"', - 'first = 1', - '[2] = ', - 'second = \"smart\"', - 'first = 2', - '[3] = ', - 'second = \"!!!\"', - 'first = 3']) - - # check access-by-index - self.expect("frame variable is[0]", - substrs = ['first = ', '0', - 'second =', 'goofy']); - - # but check that expression does not rely on us - self.expect("expression is[0]", matching=False, error=True, - substrs = ['first = ', 'goofy']) - - self.runCmd("n") - - self.expect('frame variable is', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - self.runCmd("frame variable ss -T") - - #self.runCmd("type summary add std::strstr_map strstr_map --summary-string \"map has ${svar%#} items\" -e") - #self.runCmd("type synth add std::strstr_map strstr_map -l StdMapSynthProvider") - - self.expect('frame variable ss', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable ss", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"hello\"', - 'first = \"ciao\"', - '[1] = ', - 'second = \"house\"', - 'first = \"casa\"', - '[2] = ', - 'second = \"cat\"', - 'first = \"gatto\"', - '[3] = ', - 'second = \"..is always a Mac!\"', - 'first = \"a Mac..\"']) - - self.expect("p ss", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"hello\"', - 'first = \"ciao\"', - '[1] = ', - 'second = \"house\"', - 'first = \"casa\"', - '[2] = ', - 'second = \"cat\"', - 'first = \"gatto\"', - '[3] = ', - 'second = \"..is always a Mac!\"', - 'first = \"a Mac..\"']) - - # check access-by-index - self.expect("frame variable ss[3]", - substrs = ['gatto', 'cat']); - - # but check that expression does not rely on us - self.expect("expression ss[3]", matching=False, error=True, - substrs = ['gatto']) - - self.runCmd("n") - - self.expect('frame variable ss', - substrs = ['map has 0 items', - '{}']) - if __name__ == '__main__': import atexit lldb.SBDebugger.Initialize() Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp?rev=149393&r1=149392&r2=149393&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-python-synth/main.cpp Tue Jan 31 11:50:00 2012 @@ -1,18 +1,3 @@ -#include -#include -#include -#include -typedef std::vector int_vect; -typedef std::vector string_vect; - -typedef std::list int_list; -typedef std::list string_list; - -#define intint_map std::map -#define strint_map std::map -#define intstr_map std::map -#define strstr_map std::map - struct foo { int a; @@ -73,92 +58,5 @@ 256*256*'C'+ 256*256*256*'D'); - int_vect numbers; - numbers.push_back(1); - numbers.push_back(12); - numbers.push_back(123); - numbers.push_back(1234); - numbers.push_back(12345); - numbers.push_back(123456); - numbers.push_back(1234567); - - numbers.clear(); - - numbers.push_back(7); - - string_vect strings; - strings.push_back(std::string("goofy")); - strings.push_back(std::string("is")); - strings.push_back(std::string("smart")); - - strings.push_back(std::string("!!!")); - - strings.clear(); - - int_list numbers_list; - - numbers_list.push_back(0x12345678); - numbers_list.push_back(0x11223344); - numbers_list.push_back(0xBEEFFEED); - numbers_list.push_back(0x00ABBA00); - numbers_list.push_back(0x0ABCDEF0); - numbers_list.push_back(0x0CAB0CAB); - - numbers_list.clear(); - - numbers_list.push_back(1); - numbers_list.push_back(2); - numbers_list.push_back(3); - numbers_list.push_back(4); - - string_list text_list; - text_list.push_back(std::string("goofy")); - text_list.push_back(std::string("is")); - text_list.push_back(std::string("smart")); - - text_list.push_back(std::string("!!!")); - - intint_map ii; - - ii[0] = 0; - ii[1] = 1; - ii[2] = 0; - ii[3] = 1; - ii[4] = 0; - ii[5] = 1; - ii[6] = 0; - ii[7] = 1; - ii[8] = 0; - - ii.clear(); - - strint_map si; - - si["zero"] = 0; - si["one"] = 1; - si["two"] = 2; - si["three"] = 3; - si["four"] = 4; - - si.clear(); - - intstr_map is; - - is[0] = "goofy"; - is[1] = "is"; - is[2] = "smart"; - is[3] = "!!!"; - - is.clear(); - - strstr_map ss; - - ss["ciao"] = "hello"; - ss["casa"] = "house"; - ss["gatto"] = "cat"; - ss["a Mac.."] = "..is always a Mac!"; - - ss.clear(); - return 0; } \ No newline at end of file From granata.enrico at gmail.com Tue Jan 31 15:03:57 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Tue, 31 Jan 2012 21:03:57 -0000 Subject: [Lldb-commits] [lldb] r149419 - in /lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector: Makefile TestDataFormatterStdVector.py main.cpp Message-ID: <20120131210357.842382A6C12C@llvm.org> Author: enrico Date: Tue Jan 31 15:03:57 2012 New Revision: 149419 URL: http://llvm.org/viewvc/llvm-project?rev=149419&view=rev Log: Test case for std::vector synthetic children provider Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/Makefile lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/TestDataFormatterStdVector.py lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/main.cpp Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/Makefile?rev=149419&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/Makefile (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/Makefile Tue Jan 31 15:03:57 2012 @@ -0,0 +1,5 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/TestDataFormatterStdVector.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/TestDataFormatterStdVector.py?rev=149419&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/TestDataFormatterStdVector.py (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/TestDataFormatterStdVector.py Tue Jan 31 15:03:57 2012 @@ -0,0 +1,216 @@ +""" +Test lldb data formatter subsystem. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class StdVectorDataFormatterTestCase(TestBase): + + mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "vector") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_with_dsym_and_run_command(self): + """Test data formatter commands.""" + self.buildDsym() + self.data_formatter_commands() + + def test_with_dwarf_and_run_command(self): + """Test data formatter commands.""" + self.buildDwarf() + self.data_formatter_commands() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that that file and class static variables display correctly.""" + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + self.expect("breakpoint set -f main.cpp -l %d" % self.line, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % + self.line) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # This is the function to remove the custom formats in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('type format clear', check=False) + self.runCmd('type summary clear', check=False) + self.runCmd('type filter clear', check=False) + self.runCmd('type synth clear', check=False) + self.runCmd("settings set target.max-children-count 256", check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + # empty vectors (and storage pointers SHOULD BOTH BE NULL..) + self.expect("frame variable numbers", + substrs = ['numbers = {}']) + + self.runCmd("n") + + # first value added + self.expect("frame variable numbers", + substrs = ['numbers = {', + '[0] = 1', + '}']) + + # add some more data + self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable numbers", + substrs = ['numbers = {', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '}']) + + self.expect("p numbers", + substrs = ['$', '= {', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '}']) + + + # check access to synthetic children + self.runCmd("type summary add --summary-string \"item 0 is ${var[0]}\" std::int_vect int_vect") + self.expect('frame variable numbers', + substrs = ['item 0 is 1']); + + self.runCmd("type summary add --summary-string \"item 0 is ${svar[0]}\" std::int_vect int_vect") + #import time + #time.sleep(19) + self.expect('frame variable numbers', + substrs = ['item 0 is 1']); + # move on with synths + self.runCmd("type summary delete std::int_vect") + self.runCmd("type summary delete int_vect") + + # add some more data + self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable numbers", + substrs = ['numbers = {', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) + + self.expect("p numbers", + substrs = ['$', ' = {', + '[0] = 1', + '[1] = 12', + '[2] = 123', + '[3] = 1234', + '[4] = 12345', + '[5] = 123456', + '[6] = 1234567', + '}']) + + # check access-by-index + self.expect("frame variable numbers[0]", + substrs = ['1']); + self.expect("frame variable numbers[1]", + substrs = ['12']); + self.expect("frame variable numbers[2]", + substrs = ['123']); + self.expect("frame variable numbers[3]", + substrs = ['1234']); + + # but check that expression does not rely on us + # (when expression gets to call into STL code correctly, we will have to find + # another way to check this) + self.expect("expression numbers[6]", matching=False, error=True, + substrs = ['1234567']) + + # clear out the vector and see that we do the right thing once again + self.runCmd("n") + + self.expect("frame variable numbers", + substrs = ['numbers = {}']) + + self.runCmd("n") + + # first value added + self.expect("frame variable numbers", + substrs = ['numbers = {', + '[0] = 7', + '}']) + + # check if we can display strings + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + self.runCmd("n") + + self.expect("frame variable strings", + substrs = ['goofy', + 'is', + 'smart']) + + self.expect("p strings", + substrs = ['goofy', + 'is', + 'smart']) + + # test summaries based on synthetic children + self.runCmd("type summary add std::string_vect string_vect --summary-string \"vector has ${svar%#} items\" -e") + self.expect("frame variable strings", + substrs = ['vector has 3 items', + 'goofy', + 'is', + 'smart']) + + self.expect("p strings", + substrs = ['vector has 3 items', + 'goofy', + 'is', + 'smart']) + + self.runCmd("n"); + + self.expect("frame variable strings", + substrs = ['vector has 4 items']) + + # check access-by-index + self.expect("frame variable strings[0]", + substrs = ['goofy']); + self.expect("frame variable strings[1]", + substrs = ['is']); + + # but check that expression does not rely on us + # (when expression gets to call into STL code correctly, we will have to find + # another way to check this) + self.expect("expression strings[0]", matching=False, error=True, + substrs = ['goofy']) + + self.runCmd("n") + + self.expect("frame variable strings", + substrs = ['vector has 0 items']) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/main.cpp?rev=149419&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/main.cpp (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/vector/main.cpp Tue Jan 31 15:03:57 2012 @@ -0,0 +1,31 @@ +#include +#include +typedef std::vector int_vect; +typedef std::vector string_vect; + +int main() +{ + int_vect numbers; + numbers.push_back(1); // Set break point at this line. + numbers.push_back(12); + numbers.push_back(123); + numbers.push_back(1234); + numbers.push_back(12345); + numbers.push_back(123456); + numbers.push_back(1234567); + + numbers.clear(); + + numbers.push_back(7); + + string_vect strings; + strings.push_back(std::string("goofy")); + strings.push_back(std::string("is")); + strings.push_back(std::string("smart")); + + strings.push_back(std::string("!!!")); + + strings.clear(); + + return 0; +} From granata.enrico at gmail.com Tue Jan 31 15:27:10 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Tue, 31 Jan 2012 21:27:10 -0000 Subject: [Lldb-commits] [lldb] r149420 - in /lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list: Makefile TestDataFormatterStdList.py main.cpp Message-ID: <20120131212710.2B4F92A6C12C@llvm.org> Author: enrico Date: Tue Jan 31 15:27:09 2012 New Revision: 149420 URL: http://llvm.org/viewvc/llvm-project?rev=149420&view=rev Log: Test case for std::list synthetic children provider (currently an expected failure) Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/Makefile lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/main.cpp Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/Makefile?rev=149420&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/Makefile (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/Makefile Tue Jan 31 15:27:09 2012 @@ -0,0 +1,5 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py?rev=149420&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py Tue Jan 31 15:27:09 2012 @@ -0,0 +1,453 @@ +""" +Test lldb data formatter subsystem. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class StdListDataFormatterTestCase(TestBase): + + mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "list") + + #rdar://problem/10334911 + @unittest2.expectedFailure + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_with_dsym_and_run_command(self): + """Test data formatter commands.""" + self.buildDsym() + self.data_formatter_commands() + + #rdar://problem/10334911 + @unittest2.expectedFailure + def test_with_dwarf_and_run_command(self): + """Test data formatter commands.""" + self.buildDwarf() + self.data_formatter_commands() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that that file and class static variables display correctly.""" + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + self.expect("breakpoint set -f main.cpp -l %d" % self.line, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % + self.line) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # This is the function to remove the custom formats in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('type format clear', check=False) + self.runCmd('type summary clear', check=False) + self.runCmd('type filter clear', check=False) + self.runCmd('type synth clear', check=False) + self.runCmd("settings set target.max-children-count 256", check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("frame variable numbers_list -T") + #self.runCmd("type synth add std::int_list std::string_list int_list string_list -l StdListSynthProvider") + self.runCmd("type summary add std::int_list std::string_list int_list string_list --summary-string \"list has ${svar%#} items\" -e") + self.runCmd("type format add -f hex int") + + self.expect("frame variable numbers_list --raw", matching=False, + substrs = ['list has 0 items', + '{}']) + + self.expect("frame variable numbers_list", + substrs = ['list has 0 items', + '{}']) + + self.expect("p numbers_list", + substrs = ['list has 0 items', + '{}']) + + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs = ['list has 1 items', + '[0] = ', + '0x12345678']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable numbers_list", + substrs = ['list has 4 items', + '[0] = ', + '0x12345678', + '[1] =', + '0x11223344', + '[2] =', + '0xbeeffeed', + '[3] =', + '0x00abba00']) + + self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable numbers_list", + substrs = ['list has 6 items', + '[0] = ', + '0x12345678', + '0x11223344', + '0xbeeffeed', + '0x00abba00', + '[4] =', + '0x0abcdef0', + '[5] =', + '0x0cab0cab']) + + self.expect("p numbers_list", + substrs = ['list has 6 items', + '[0] = ', + '0x12345678', + '0x11223344', + '0xbeeffeed', + '0x00abba00', + '[4] =', + '0x0abcdef0', + '[5] =', + '0x0cab0cab']) + + # check access-by-index + self.expect("frame variable numbers_list[0]", + substrs = ['0x12345678']); + self.expect("frame variable numbers_list[1]", + substrs = ['0x11223344']); + + # but check that expression does not rely on us + self.expect("expression numbers_list[0]", matching=False, error=True, + substrs = ['0x12345678']) + + self.runCmd("n") + + self.expect("frame variable numbers_list", + substrs = ['list has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable numbers_list", + substrs = ['list has 4 items', + '[0] = ', '1', + '[1] = ', '2', + '[2] = ', '3', + '[3] = ', '4']) + + self.runCmd("type format delete int") + + self.runCmd("n") + + self.expect("frame variable text_list", + substrs = ['list has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable text_list", + substrs = ['list has 4 items', + '[0]', 'goofy', + '[1]', 'is', + '[2]', 'smart', + '[3]', '!!!']) + + self.expect("p text_list", + substrs = ['list has 4 items', + '[0] = \"goofy\"', + '[1] = \"is\"', + '[2] = \"smart\"', + '[3] = \"!!!\"']) + + # check access-by-index + self.expect("frame variable text_list[0]", + substrs = ['goofy']); + self.expect("frame variable text_list[3]", + substrs = ['!!!']); + + # but check that expression does not rely on us + self.expect("expression text_list[0]", matching=False, error=True, + substrs = ['goofy']) + + # now std::map + # also take a chance to test regex synth here + + self.runCmd("n") + self.runCmd("frame variable ii -T") + + #self.runCmd("script from StdMapSynthProvider import *") + self.runCmd("type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e") + + #import time + #time.sleep(30) + + #self.runCmd("type synth add -x \"std::map<\" -l StdMapSynthProvider") + + + self.expect('frame variable ii', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n"); + + self.expect('frame variable ii', + substrs = ['map has 2 items', + '[0] = {', + 'first = 0', + 'second = 0', + '[1] = {', + 'first = 1', + 'second = 1']) + + self.runCmd("n");self.runCmd("n"); + + self.expect('frame variable ii', + substrs = ['map has 4 items', + '[2] = {', + 'first = 2', + 'second = 0', + '[3] = {', + 'first = 3', + 'second = 1']) + + self.runCmd("n");self.runCmd("n"); + self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable ii", + substrs = ['map has 9 items', + '[5] = {', + 'first = 5', + 'second = 0', + '[7] = {', + 'first = 7', + 'second = 1']) + + self.expect("p ii", + substrs = ['map has 9 items', + '[5] = {', + 'first = 5', + 'second = 0', + '[7] = {', + 'first = 7', + 'second = 1']) + + # check access-by-index + self.expect("frame variable ii[0]", + substrs = ['first = 0', + 'second = 0']); + self.expect("frame variable ii[3]", + substrs = ['first =', + 'second =']); + + # but check that expression does not rely on us + self.expect("expression ii[0]", matching=False, error=True, + substrs = ['first = 0']) + + self.runCmd("n") + + self.expect('frame variable ii', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + self.runCmd("frame variable si -T") + + #self.runCmd("type summary add std::strint_map strint_map --summary-string \"map has ${svar%#} items\" -e") + #self.runCmd("type synth add std::strint_map strint_map -l StdMapSynthProvider") + + self.expect('frame variable si', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + + self.expect('frame variable si', + substrs = ['map has 1 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable si", + substrs = ['map has 5 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3', + '[4] = ', + 'first = \"four\"', + 'second = 4']) + + self.expect("p si", + substrs = ['map has 5 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3', + '[4] = ', + 'first = \"four\"', + 'second = 4']) + + # check access-by-index + self.expect("frame variable si[0]", + substrs = ['first = ', 'four', + 'second = 4']); + + # but check that expression does not rely on us + self.expect("expression si[0]", matching=False, error=True, + substrs = ['first = ', 'zero']) + + self.runCmd("n") + + self.expect('frame variable si', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + self.runCmd("frame variable is -T") + + #self.runCmd("type summary add std::intstr_map intstr_map --summary-string \"map has ${svar%#} items\" -e") + #self.runCmd("type synth add std::intstr_map intstr_map -l StdMapSynthProvider") + + self.expect('frame variable is', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable is", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"goofy\"', + 'first = 0', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + self.expect("p is", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"goofy\"', + 'first = 0', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + # check access-by-index + self.expect("frame variable is[0]", + substrs = ['first = ', '0', + 'second =', 'goofy']); + + # but check that expression does not rely on us + self.expect("expression is[0]", matching=False, error=True, + substrs = ['first = ', 'goofy']) + + self.runCmd("n") + + self.expect('frame variable is', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + self.runCmd("frame variable ss -T") + + #self.runCmd("type summary add std::strstr_map strstr_map --summary-string \"map has ${svar%#} items\" -e") + #self.runCmd("type synth add std::strstr_map strstr_map -l StdMapSynthProvider") + + self.expect('frame variable ss', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable ss", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"', + '[3] = ', + 'second = \"..is always a Mac!\"', + 'first = \"a Mac..\"']) + + self.expect("p ss", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"', + '[3] = ', + 'second = \"..is always a Mac!\"', + 'first = \"a Mac..\"']) + + # check access-by-index + self.expect("frame variable ss[3]", + substrs = ['gatto', 'cat']); + + # but check that expression does not rely on us + self.expect("expression ss[3]", matching=False, error=True, + substrs = ['gatto']) + + self.runCmd("n") + + self.expect('frame variable ss', + substrs = ['map has 0 items', + '{}']) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/main.cpp?rev=149420&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/main.cpp (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/main.cpp Tue Jan 31 15:27:09 2012 @@ -0,0 +1,33 @@ +#include +#include + +typedef std::list int_list; +typedef std::list string_list; + +int main() +{ + int_list numbers_list; + + numbers_list.push_back(0x12345678); // Set break point at this line. + numbers_list.push_back(0x11223344); + numbers_list.push_back(0xBEEFFEED); + numbers_list.push_back(0x00ABBA00); + numbers_list.push_back(0x0ABCDEF0); + numbers_list.push_back(0x0CAB0CAB); + + numbers_list.clear(); + + numbers_list.push_back(1); + numbers_list.push_back(2); + numbers_list.push_back(3); + numbers_list.push_back(4); + + string_list text_list; + text_list.push_back(std::string("goofy")); + text_list.push_back(std::string("is")); + text_list.push_back(std::string("smart")); + + text_list.push_back(std::string("!!!")); + + return 0; +} \ No newline at end of file From granata.enrico at gmail.com Tue Jan 31 15:30:00 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Tue, 31 Jan 2012 21:30:00 -0000 Subject: [Lldb-commits] [lldb] r149421 - in /lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map: Makefile TestDataFormatterStdMap.py main.cpp Message-ID: <20120131213000.7CD1E2A6C12C@llvm.org> Author: enrico Date: Tue Jan 31 15:30:00 2012 New Revision: 149421 URL: http://llvm.org/viewvc/llvm-project?rev=149421&view=rev Log: Test case for std::map synthetic children provider (currently an expected failure) Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/Makefile lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/main.cpp Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/Makefile?rev=149421&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/Makefile (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/Makefile Tue Jan 31 15:30:00 2012 @@ -0,0 +1,5 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py?rev=149421&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py Tue Jan 31 15:30:00 2012 @@ -0,0 +1,317 @@ +""" +Test lldb data formatter subsystem. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class StdMapDataFormatterTestCase(TestBase): + + mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "map") + + #rdar://problem/10334911 + #@unittest2.expectedFailure + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_with_dsym_and_run_command(self): + """Test data formatter commands.""" + self.buildDsym() + self.data_formatter_commands() + + #rdar://problem/10334911 + #@unittest2.expectedFailure + def test_with_dwarf_and_run_command(self): + """Test data formatter commands.""" + self.buildDwarf() + self.data_formatter_commands() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that that file and class static variables display correctly.""" + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + self.expect("breakpoint set -f main.cpp -l %d" % self.line, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % + self.line) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # This is the function to remove the custom formats in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('type format clear', check=False) + self.runCmd('type summary clear', check=False) + self.runCmd('type filter clear', check=False) + self.runCmd('type synth clear', check=False) + self.runCmd("settings set target.max-children-count 256", check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.runCmd("frame variable ii -T") + + self.runCmd("type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e") + + self.expect('frame variable ii', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n"); + + self.expect('frame variable ii', + substrs = ['map has 2 items', + '[0] = {', + 'first = 0', + 'second = 0', + '[1] = {', + 'first = 1', + 'second = 1']) + + self.runCmd("n");self.runCmd("n"); + + self.expect('frame variable ii', + substrs = ['map has 4 items', + '[2] = {', + 'first = 2', + 'second = 0', + '[3] = {', + 'first = 3', + 'second = 1']) + + self.runCmd("n");self.runCmd("n"); + self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable ii", + substrs = ['map has 9 items', + '[5] = {', + 'first = 5', + 'second = 0', + '[7] = {', + 'first = 7', + 'second = 1']) + + self.expect("p ii", + substrs = ['map has 9 items', + '[5] = {', + 'first = 5', + 'second = 0', + '[7] = {', + 'first = 7', + 'second = 1']) + + # check access-by-index + self.expect("frame variable ii[0]", + substrs = ['first = 0', + 'second = 0']); + self.expect("frame variable ii[3]", + substrs = ['first =', + 'second =']); + + # but check that expression does not rely on us + self.expect("expression ii[0]", matching=False, error=True, + substrs = ['first = 0']) + + self.runCmd("n") + + self.expect('frame variable ii', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + self.runCmd("frame variable si -T") + + #self.runCmd("type summary add std::strint_map strint_map --summary-string \"map has ${svar%#} items\" -e") + #self.runCmd("type synth add std::strint_map strint_map -l StdMapSynthProvider") + + self.expect('frame variable si', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + + self.expect('frame variable si', + substrs = ['map has 1 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable si", + substrs = ['map has 5 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3', + '[4] = ', + 'first = \"four\"', + 'second = 4']) + + self.expect("p si", + substrs = ['map has 5 items', + '[0] = ', + 'first = \"zero\"', + 'second = 0', + '[1] = ', + 'first = \"one\"', + 'second = 1', + '[2] = ', + 'first = \"two\"', + 'second = 2', + '[3] = ', + 'first = \"three\"', + 'second = 3', + '[4] = ', + 'first = \"four\"', + 'second = 4']) + + # check access-by-index + self.expect("frame variable si[0]", + substrs = ['first = ', 'four', + 'second = 4']); + + # but check that expression does not rely on us + self.expect("expression si[0]", matching=False, error=True, + substrs = ['first = ', 'zero']) + + self.runCmd("n") + + self.expect('frame variable si', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + self.runCmd("frame variable is -T") + + #self.runCmd("type summary add std::intstr_map intstr_map --summary-string \"map has ${svar%#} items\" -e") + #self.runCmd("type synth add std::intstr_map intstr_map -l StdMapSynthProvider") + + self.expect('frame variable is', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable is", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"goofy\"', + 'first = 0', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + self.expect("p is", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"goofy\"', + 'first = 0', + '[1] = ', + 'second = \"is\"', + 'first = 1', + '[2] = ', + 'second = \"smart\"', + 'first = 2', + '[3] = ', + 'second = \"!!!\"', + 'first = 3']) + + # check access-by-index + self.expect("frame variable is[0]", + substrs = ['first = ', '0', + 'second =', 'goofy']); + + # but check that expression does not rely on us + self.expect("expression is[0]", matching=False, error=True, + substrs = ['first = ', 'goofy']) + + self.runCmd("n") + + self.expect('frame variable is', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n") + self.runCmd("frame variable ss -T") + + self.expect('frame variable ss', + substrs = ['map has 0 items', + '{}']) + + self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); + + self.expect("frame variable ss", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"', + '[3] = ', + 'second = \"..is always a Mac!\"', + 'first = \"a Mac..\"']) + + self.expect("p ss", + substrs = ['map has 4 items', + '[0] = ', + 'second = \"hello\"', + 'first = \"ciao\"', + '[1] = ', + 'second = \"house\"', + 'first = \"casa\"', + '[2] = ', + 'second = \"cat\"', + 'first = \"gatto\"', + '[3] = ', + 'second = \"..is always a Mac!\"', + 'first = \"a Mac..\"']) + + # check access-by-index + self.expect("frame variable ss[3]", + substrs = ['gatto', 'cat']); + + # but check that expression does not rely on us + self.expect("expression ss[3]", matching=False, error=True, + substrs = ['gatto']) + + self.runCmd("n") + + self.expect('frame variable ss', + substrs = ['map has 0 items', + '{}']) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/main.cpp?rev=149421&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/main.cpp (added) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/main.cpp Tue Jan 31 15:30:00 2012 @@ -0,0 +1,55 @@ +#include +#include + +#define intint_map std::map +#define strint_map std::map +#define intstr_map std::map +#define strstr_map std::map + + +int main() +{ + intint_map ii; + + ii[0] = 0; // Set break point at this line. + ii[1] = 1; + ii[2] = 0; + ii[3] = 1; + ii[4] = 0; + ii[5] = 1; + ii[6] = 0; + ii[7] = 1; + ii[8] = 0; + + ii.clear(); + + strint_map si; + + si["zero"] = 0; + si["one"] = 1; + si["two"] = 2; + si["three"] = 3; + si["four"] = 4; + + si.clear(); + + intstr_map is; + + is[0] = "goofy"; + is[1] = "is"; + is[2] = "smart"; + is[3] = "!!!"; + + is.clear(); + + strstr_map ss; + + ss["ciao"] = "hello"; + ss["casa"] = "house"; + ss["gatto"] = "cat"; + ss["a Mac.."] = "..is always a Mac!"; + + ss.clear(); + + return 0; +} \ No newline at end of file From jingham at apple.com Tue Jan 31 17:09:21 2012 From: jingham at apple.com (Jim Ingham) Date: Tue, 31 Jan 2012 23:09:21 -0000 Subject: [Lldb-commits] [lldb] r149443 - in /lldb/trunk: include/lldb/Target/Thread.h source/Target/Thread.cpp source/Target/ThreadList.cpp Message-ID: <20120131230921.2C1E32A6C12D@llvm.org> Author: jingham Date: Tue Jan 31 17:09:20 2012 New Revision: 149443 URL: http://llvm.org/viewvc/llvm-project?rev=149443&view=rev Log: Threads now store their "temporary" resume state, so we know whether they were suspended in the most recent step, and if they weren't allowed to run, don't ask questions about their state unless explicitly requested to do so. Modified: lldb/trunk/include/lldb/Target/Thread.h lldb/trunk/source/Target/Thread.cpp lldb/trunk/source/Target/ThreadList.cpp Modified: lldb/trunk/include/lldb/Target/Thread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=149443&r1=149442&r2=149443&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Thread.h (original) +++ lldb/trunk/include/lldb/Target/Thread.h Tue Jan 31 17:09:20 2012 @@ -807,6 +807,18 @@ StackFrameList & GetStackFrameList (); + lldb::StateType GetTemporaryResumeState() + { + return m_temporary_resume_state; + } + + lldb::StateType SetTemporaryResumeState(lldb::StateType resume_state) + { + lldb::StateType old_temp_resume_state = m_temporary_resume_state; + m_temporary_resume_state = resume_state; + return old_temp_resume_state; + } + struct ThreadState { uint32_t orig_stop_id; @@ -829,7 +841,9 @@ lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops. lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped. int m_resume_signal; ///< The signal that should be used when continuing this thread. - lldb::StateType m_resume_state; ///< The state that indicates what this thread should do when the process is resumed. + lldb::StateType m_resume_state; ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic. + lldb::StateType m_temporary_resume_state; ///< This state records what the thread was told to do by the thread plan logic for the current resume. + /// It gets set in Thread::WillResume. std::auto_ptr m_unwinder_ap; bool m_destroy_called; // This is used internally to make sure derived Thread classes call DestroyThread. uint32_t m_thread_stop_reason_stop_id; // This is the stop id for which the StopInfo is valid. Can use this so you know that Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=149443&r1=149442&r2=149443&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Tue Jan 31 17:09:20 2012 @@ -58,6 +58,7 @@ m_prev_frames_sp (), m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), m_resume_state (eStateRunning), + m_temporary_resume_state (eStateRunning), m_unwinder_ap (), m_destroy_called (false), m_thread_stop_reason_stop_id (0) @@ -227,9 +228,20 @@ m_completed_plan_stack.clear(); m_discarded_plan_stack.clear(); - StopInfo *stop_info = GetPrivateStopReason().get(); - if (stop_info) - stop_info->WillResume (resume_state); + SetTemporaryResumeState(resume_state); + + // This is a little dubious, but we are trying to limit how often we actually fetch stop info from + // the target, 'cause that slows down single stepping. So assume that if we got to the point where + // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know + // about the fact that we are resuming... + const uint32_t process_stop_id = GetProcess().GetStopID(); + if (m_thread_stop_reason_stop_id == process_stop_id && + (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid())) + { + StopInfo *stop_info = GetPrivateStopReason().get(); + if (stop_info) + stop_info->WillResume (resume_state); + } // Tell all the plans that we are about to resume in case they need to clear any state. // We distinguish between the plan on the top of the stack and the lower @@ -260,8 +272,49 @@ bool should_stop = true; LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + + if (GetResumeState () == eStateSuspended) + { + if (log) + log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", + __FUNCTION__, + GetID ()); +// log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", +// __FUNCTION__, +// GetID (), +// GetRegisterContext()->GetPC()); + return false; + } + + if (GetTemporaryResumeState () == eStateSuspended) + { + if (log) + log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)", + __FUNCTION__, + GetID ()); +// log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", +// __FUNCTION__, +// GetID (), +// GetRegisterContext()->GetPC()); + return false; + } + + if (ThreadStoppedForAReason() == false) + { + if (log) + log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)", + __FUNCTION__, + GetID (), + GetRegisterContext()->GetPC()); + return false; + } + if (log) { + log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx", + __FUNCTION__, + GetID (), + GetRegisterContext()->GetPC()); log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); StreamString s; s.IndentMore(); @@ -401,6 +454,8 @@ Thread::ShouldReportStop (Event* event_ptr) { StateType thread_state = GetResumeState (); + StateType temp_thread_state = GetTemporaryResumeState(); + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); if (thread_state == eStateSuspended || thread_state == eStateInvalid) @@ -410,6 +465,20 @@ return eVoteNoOpinion; } + if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) + { + if (log) + log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (temporary state was suspended or invalid)\n", GetID(), eVoteNoOpinion); + return eVoteNoOpinion; + } + + if (!ThreadStoppedForAReason()) + { + if (log) + log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (thread didn't stop for a reason.)\n", GetID(), eVoteNoOpinion); + return eVoteNoOpinion; + } + if (m_completed_plan_stack.size() > 0) { // Don't use GetCompletedPlan here, since that suppresses private plans. Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=149443&r1=149442&r2=149443&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Tue Jan 31 17:09:20 2012 @@ -192,38 +192,10 @@ log->Printf ("ThreadList::%s: %zu threads", __FUNCTION__, m_threads.size()); } - // Run through the threads and ask whether we should stop. Don't ask - // suspended threads, however, it makes more sense for them to preserve their - // state across the times the process runs but they don't get a chance to. for (pos = m_threads.begin(); pos != end; ++pos) { ThreadSP thread_sp(*pos); - if (thread_sp->GetResumeState () == eStateSuspended) - { - if (log) - log->Printf ("ThreadList::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)", - __FUNCTION__, - thread_sp->GetID (), - thread_sp->GetRegisterContext()->GetPC()); - continue; - } - - if (thread_sp->ThreadStoppedForAReason() == false) - { - if (log) - log->Printf ("ThreadList::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)", - __FUNCTION__, - thread_sp->GetID (), - thread_sp->GetRegisterContext()->GetPC()); - continue; - } - - if (log) - log->Printf ("ThreadList::%s for tid = 0x%4.4llx, pc = 0x%16.16llx", - __FUNCTION__, - thread_sp->GetID (), - thread_sp->GetRegisterContext()->GetPC()); const bool thread_should_stop = thread_sp->ShouldStop(event_ptr); if (thread_should_stop) should_stop |= true; @@ -263,41 +235,31 @@ for (pos = m_threads.begin(); pos != end; ++pos) { ThreadSP thread_sp(*pos); - if (thread_sp->ThreadStoppedForAReason() && (thread_sp->GetResumeState () != eStateSuspended)) + const Vote vote = thread_sp->ShouldReportStop (event_ptr); + switch (vote) { - const Vote vote = thread_sp->ShouldReportStop (event_ptr); - if (log) - log->Printf ("ThreadList::%s thread 0x%4.4llx: pc = 0x%16.16llx, vote = %s", - __FUNCTION__, - thread_sp->GetID (), - thread_sp->GetRegisterContext()->GetPC(), - GetVoteAsCString (vote)); - switch (vote) - { - case eVoteNoOpinion: - continue; + case eVoteNoOpinion: + continue; - case eVoteYes: - result = eVoteYes; - break; + case eVoteYes: + result = eVoteYes; + break; - case eVoteNo: - if (result == eVoteNoOpinion) - { - result = eVoteNo; - } - else - { - if (log) - log->Printf ("ThreadList::%s thread 0x%4.4llx: pc = 0x%16.16llx voted %s, but lost out because result was %s", - __FUNCTION__, - thread_sp->GetID (), - thread_sp->GetRegisterContext()->GetPC(), - GetVoteAsCString (vote), - GetVoteAsCString (result)); - } - break; + case eVoteNo: + if (result == eVoteNoOpinion) + { + result = eVoteNo; + } + else + { + if (log) + log->Printf ("ThreadList::%s thread 0x%4.4llx: voted %s, but lost out because result was %s", + __FUNCTION__, + thread_sp->GetID (), + GetVoteAsCString (vote), + GetVoteAsCString (result)); } + break; } } if (log) From gclayton at apple.com Tue Jan 31 17:19:33 2012 From: gclayton at apple.com (Greg Clayton) Date: Tue, 31 Jan 2012 23:19:33 -0000 Subject: [Lldb-commits] [lldb] r149447 - in /lldb/trunk: include/lldb/API/SBType.h scripts/Python/interface/SBType.i source/API/SBType.cpp test/python_api/default-constructor/sb_module.py test/python_api/default-constructor/sb_target.py test/python_api/default-constructor/sb_value.py Message-ID: <20120131231933.83CAB2A6C12D@llvm.org> Author: gclayton Date: Tue Jan 31 17:19:33 2012 New Revision: 149447 URL: http://llvm.org/viewvc/llvm-project?rev=149447&view=rev Log: Added fuzz testing for when we call API calls with an invalid object. We previously weren't catching that SBValue::Cast(...) would crash if we had an invalid (empty) SBValue object. Cleaned up the SBType API a bit. Modified: lldb/trunk/include/lldb/API/SBType.h lldb/trunk/scripts/Python/interface/SBType.i lldb/trunk/source/API/SBType.cpp lldb/trunk/test/python_api/default-constructor/sb_module.py lldb/trunk/test/python_api/default-constructor/sb_target.py lldb/trunk/test/python_api/default-constructor/sb_value.py Modified: lldb/trunk/include/lldb/API/SBType.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=149447&r1=149446&r2=149447&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBType.h (original) +++ lldb/trunk/include/lldb/API/SBType.h Tue Jan 31 17:19:33 2012 @@ -138,8 +138,6 @@ GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); -protected: - #ifndef SWIG lldb::SBType & operator = (const lldb::SBType &rhs); @@ -149,7 +147,11 @@ bool operator != (lldb::SBType &rhs); +#endif +protected: + +#ifndef SWIG lldb_private::TypeImpl & ref (); @@ -157,7 +159,7 @@ ref () const; void - reset(const lldb::TypeImplSP &type_impl_sp); + SetSP (const lldb::TypeImplSP &type_impl_sp); #endif Modified: lldb/trunk/scripts/Python/interface/SBType.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBType.i?rev=149447&r1=149446&r2=149447&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBType.i (original) +++ lldb/trunk/scripts/Python/interface/SBType.i Tue Jan 31 17:19:33 2012 @@ -131,6 +131,8 @@ class SBType { public: + SBType (); + SBType (const lldb::SBType &rhs); ~SBType (); Modified: lldb/trunk/source/API/SBType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=149447&r1=149446&r2=149447&view=diff ============================================================================== --- lldb/trunk/source/API/SBType.cpp (original) +++ lldb/trunk/source/API/SBType.cpp Tue Jan 31 17:19:33 2012 @@ -84,7 +84,7 @@ } void -SBType::reset(const lldb::TypeImplSP &type_impl_sp) +SBType::SetSP (const lldb::TypeImplSP &type_impl_sp) { m_opaque_sp = type_impl_sp; } @@ -556,7 +556,7 @@ SBType sb_type; if (m_opaque_ap.get()) { - sb_type.reset (m_opaque_ap->GetTypeImpl()); + sb_type.SetSP (m_opaque_ap->GetTypeImpl()); } return sb_type; Modified: lldb/trunk/test/python_api/default-constructor/sb_module.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_module.py?rev=149447&r1=149446&r2=149447&view=diff ============================================================================== --- lldb/trunk/test/python_api/default-constructor/sb_module.py (original) +++ lldb/trunk/test/python_api/default-constructor/sb_module.py Tue Jan 31 17:19:33 2012 @@ -23,4 +23,6 @@ print symbol for symbol in obj: print symbol - + obj.GetAddressByteSize() + obj.GetByteOrder() + obj.GetTriple() Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=149447&r1=149446&r2=149447&view=diff ============================================================================== --- lldb/trunk/test/python_api/default-constructor/sb_target.py (original) +++ lldb/trunk/test/python_api/default-constructor/sb_target.py Tue Jan 31 17:19:33 2012 @@ -49,6 +49,9 @@ obj.EnableAllWatchpoints() obj.DisableAllWatchpoints() obj.DeleteAllWatchpoints() + obj.GetAddressByteSize() + obj.GetByteOrder() + obj.GetTriple() obj.WatchAddress(123, 8, True, True) obj.GetBroadcaster() obj.GetDescription(lldb.SBStream(), lldb.eDescriptionLevelBrief) Modified: lldb/trunk/test/python_api/default-constructor/sb_value.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_value.py?rev=149447&r1=149446&r2=149447&view=diff ============================================================================== --- lldb/trunk/test/python_api/default-constructor/sb_value.py (original) +++ lldb/trunk/test/python_api/default-constructor/sb_value.py Tue Jan 31 17:19:33 2012 @@ -7,6 +7,7 @@ def fuzz_obj(obj): obj.GetError() + obj.GetID() obj.GetName() obj.GetTypeName() obj.GetByteSize() @@ -37,3 +38,29 @@ obj.WatchPointee(True, False, True) for child_val in obj: print child_val + error = lldb.SBError() + obj.GetValueAsSigned (error, 0) + obj.GetValueAsUnsigned (error, 0) + obj.GetValueAsSigned(0) + obj.GetValueAsUnsigned(0) + obj.GetDynamicValue (lldb.eNoDynamicValues) + obj.GetStaticValue () + obj.IsDynamic() + invalid_type = lldb.SBType() + obj.CreateChildAtOffset ("a", 12, invalid_type) + obj.Cast (invalid_type) + obj.CreateValueFromExpression ("pt->x", "pt->x") + obj.CreateValueFromAddress ("x", 0x123, invalid_type) + invalid_data = lldb.SBData() + obj.CreateValueFromData ("x", invalid_data, invalid_type) + obj.GetValueForExpressionPath("[0]") + obj.AddressOf() + obj.GetLoadAddress() + obj.GetAddress() + obj.GetPointeeData (0, 1) + obj.GetData () + obj.GetTarget() + obj.GetProcess() + obj.GetThread() + obj.GetFrame() + obj.GetType() From granata.enrico at gmail.com Tue Jan 31 18:43:34 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Wed, 01 Feb 2012 00:43:34 -0000 Subject: [Lldb-commits] [lldb] r149461 - /lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py Message-ID: <20120201004334.107A32A6C12C@llvm.org> Author: enrico Date: Tue Jan 31 18:43:33 2012 New Revision: 149461 URL: http://llvm.org/viewvc/llvm-project?rev=149461&view=rev Log: remove spurious leftover code from std::list testcase Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py?rev=149461&r1=149460&r2=149461&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py Tue Jan 31 18:43:33 2012 @@ -167,10 +167,10 @@ self.expect("p text_list", substrs = ['list has 4 items', - '[0] = \"goofy\"', - '[1] = \"is\"', - '[2] = \"smart\"', - '[3] = \"!!!\"']) + '\"goofy\"', + '\"is\"', + '\"smart\"', + '\"!!!\"']) # check access-by-index self.expect("frame variable text_list[0]", @@ -182,270 +182,6 @@ self.expect("expression text_list[0]", matching=False, error=True, substrs = ['goofy']) - # now std::map - # also take a chance to test regex synth here - - self.runCmd("n") - self.runCmd("frame variable ii -T") - - #self.runCmd("script from StdMapSynthProvider import *") - self.runCmd("type summary add -x \"std::map<\" --summary-string \"map has ${svar%#} items\" -e") - - #import time - #time.sleep(30) - - #self.runCmd("type synth add -x \"std::map<\" -l StdMapSynthProvider") - - - self.expect('frame variable ii', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n"); - - self.expect('frame variable ii', - substrs = ['map has 2 items', - '[0] = {', - 'first = 0', - 'second = 0', - '[1] = {', - 'first = 1', - 'second = 1']) - - self.runCmd("n");self.runCmd("n"); - - self.expect('frame variable ii', - substrs = ['map has 4 items', - '[2] = {', - 'first = 2', - 'second = 0', - '[3] = {', - 'first = 3', - 'second = 1']) - - self.runCmd("n");self.runCmd("n"); - self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable ii", - substrs = ['map has 9 items', - '[5] = {', - 'first = 5', - 'second = 0', - '[7] = {', - 'first = 7', - 'second = 1']) - - self.expect("p ii", - substrs = ['map has 9 items', - '[5] = {', - 'first = 5', - 'second = 0', - '[7] = {', - 'first = 7', - 'second = 1']) - - # check access-by-index - self.expect("frame variable ii[0]", - substrs = ['first = 0', - 'second = 0']); - self.expect("frame variable ii[3]", - substrs = ['first =', - 'second =']); - - # but check that expression does not rely on us - self.expect("expression ii[0]", matching=False, error=True, - substrs = ['first = 0']) - - self.runCmd("n") - - self.expect('frame variable ii', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - self.runCmd("frame variable si -T") - - #self.runCmd("type summary add std::strint_map strint_map --summary-string \"map has ${svar%#} items\" -e") - #self.runCmd("type synth add std::strint_map strint_map -l StdMapSynthProvider") - - self.expect('frame variable si', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - - self.expect('frame variable si', - substrs = ['map has 1 items', - '[0] = ', - 'first = \"zero\"', - 'second = 0']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable si", - substrs = ['map has 5 items', - '[0] = ', - 'first = \"zero\"', - 'second = 0', - '[1] = ', - 'first = \"one\"', - 'second = 1', - '[2] = ', - 'first = \"two\"', - 'second = 2', - '[3] = ', - 'first = \"three\"', - 'second = 3', - '[4] = ', - 'first = \"four\"', - 'second = 4']) - - self.expect("p si", - substrs = ['map has 5 items', - '[0] = ', - 'first = \"zero\"', - 'second = 0', - '[1] = ', - 'first = \"one\"', - 'second = 1', - '[2] = ', - 'first = \"two\"', - 'second = 2', - '[3] = ', - 'first = \"three\"', - 'second = 3', - '[4] = ', - 'first = \"four\"', - 'second = 4']) - - # check access-by-index - self.expect("frame variable si[0]", - substrs = ['first = ', 'four', - 'second = 4']); - - # but check that expression does not rely on us - self.expect("expression si[0]", matching=False, error=True, - substrs = ['first = ', 'zero']) - - self.runCmd("n") - - self.expect('frame variable si', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - self.runCmd("frame variable is -T") - - #self.runCmd("type summary add std::intstr_map intstr_map --summary-string \"map has ${svar%#} items\" -e") - #self.runCmd("type synth add std::intstr_map intstr_map -l StdMapSynthProvider") - - self.expect('frame variable is', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable is", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"goofy\"', - 'first = 0', - '[1] = ', - 'second = \"is\"', - 'first = 1', - '[2] = ', - 'second = \"smart\"', - 'first = 2', - '[3] = ', - 'second = \"!!!\"', - 'first = 3']) - - self.expect("p is", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"goofy\"', - 'first = 0', - '[1] = ', - 'second = \"is\"', - 'first = 1', - '[2] = ', - 'second = \"smart\"', - 'first = 2', - '[3] = ', - 'second = \"!!!\"', - 'first = 3']) - - # check access-by-index - self.expect("frame variable is[0]", - substrs = ['first = ', '0', - 'second =', 'goofy']); - - # but check that expression does not rely on us - self.expect("expression is[0]", matching=False, error=True, - substrs = ['first = ', 'goofy']) - - self.runCmd("n") - - self.expect('frame variable is', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n") - self.runCmd("frame variable ss -T") - - #self.runCmd("type summary add std::strstr_map strstr_map --summary-string \"map has ${svar%#} items\" -e") - #self.runCmd("type synth add std::strstr_map strstr_map -l StdMapSynthProvider") - - self.expect('frame variable ss', - substrs = ['map has 0 items', - '{}']) - - self.runCmd("n");self.runCmd("n");self.runCmd("n");self.runCmd("n"); - - self.expect("frame variable ss", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"hello\"', - 'first = \"ciao\"', - '[1] = ', - 'second = \"house\"', - 'first = \"casa\"', - '[2] = ', - 'second = \"cat\"', - 'first = \"gatto\"', - '[3] = ', - 'second = \"..is always a Mac!\"', - 'first = \"a Mac..\"']) - - self.expect("p ss", - substrs = ['map has 4 items', - '[0] = ', - 'second = \"hello\"', - 'first = \"ciao\"', - '[1] = ', - 'second = \"house\"', - 'first = \"casa\"', - '[2] = ', - 'second = \"cat\"', - 'first = \"gatto\"', - '[3] = ', - 'second = \"..is always a Mac!\"', - 'first = \"a Mac..\"']) - - # check access-by-index - self.expect("frame variable ss[3]", - substrs = ['gatto', 'cat']); - - # but check that expression does not rely on us - self.expect("expression ss[3]", matching=False, error=True, - substrs = ['gatto']) - - self.runCmd("n") - - self.expect('frame variable ss', - substrs = ['map has 0 items', - '{}']) - if __name__ == '__main__': import atexit lldb.SBDebugger.Initialize() From gclayton at apple.com Tue Jan 31 19:46:19 2012 From: gclayton at apple.com (Greg Clayton) Date: Wed, 01 Feb 2012 01:46:19 -0000 Subject: [Lldb-commits] [lldb] r149464 - in /lldb/trunk: scripts/Python/python-extensions.swig source/Target/ObjCLanguageRuntime.cpp Message-ID: <20120201014619.D0AC02A6C12C@llvm.org> Author: gclayton Date: Tue Jan 31 19:46:19 2012 New Revision: 149464 URL: http://llvm.org/viewvc/llvm-project?rev=149464&view=rev Log: Added a new class to the lldb python module: lldb.value() It it designed to be given a lldb.SBValue object and it allows natural use of a variable value: pt = lldb.value(lldb.frame.FindVariable("pt")) print pt print pt.x print pt.y pt = lldb.frame.FindVariable("rectangle_array") print rectangle_array[12] print rectangle_array[5].origin.x Note that array access works just fine and works on arrays or pointers: pt = lldb.frame.FindVariable("point_ptr") print point_ptr[5].y Also note that pointer child accesses are done using a "." instead of "->": print point_ptr.x Modified: lldb/trunk/scripts/Python/python-extensions.swig lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Modified: lldb/trunk/scripts/Python/python-extensions.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=149464&r1=149463&r2=149464&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-extensions.swig (original) +++ lldb/trunk/scripts/Python/python-extensions.swig Tue Jan 31 19:46:19 2012 @@ -182,3 +182,187 @@ } } +%pythoncode %{ + +class value(object): + '''A class designed to wrap lldb.SBValue() objects so the resulting object + can be used as a variable would be in code. So if you have a Point structure + variable in your code in the current frame named "pt", you can initialize an instance + of this class with it: + + pt = lldb.value(lldb.frame.FindVariable("pt")) + print pt + print pt.x + print pt.y + + pt = lldb.value(lldb.frame.FindVariable("rectangle_array")) + print rectangle_array[12] + print rectangle_array[5].origin.x''' + def __init__(self, sbvalue): + self.sbvalue = sbvalue + + def __nonzero__(self): + return self.sbvalue.__nonzero__() + + def __repr__(self): + return self.sbvalue.__repr__() + + def __str__(self): + return self.sbvalue.__str__() + + def __getitem__(self, key): + # Allow array access if this value has children... + if type(key) is int: + return value(self.sbvalue.GetValueForExpressionPath("[%i]" % key)) + raise TypeError + + def __getattr__(self, name): + child_sbvalue = self.sbvalue.GetChildMemberWithName (name) + if child_sbvalue: + return value(child_sbvalue) + raise AttributeError + + def __add__(self, other): + return int(self) + int(other) + + def __sub__(self, other): + return int(self) - int(other) + + def __mul__(self, other): + return int(self) * int(other) + + def __floordiv__(self, other): + return int(self) // int(other) + + def __mod__(self, other): + return int(self) % int(other) + + def __divmod__(self, other): + return int(self) % int(other) + + def __pow__(self, other): + return int(self) ** int(other) + + def __lshift__(self, other): + return int(self) << int(other) + + def __rshift__(self, other): + return int(self) >> int(other) + + def __and__(self, other): + return int(self) & int(other) + + def __xor__(self, other): + return int(self) ^ int(other) + + def __or__(self, other): + return int(self) | int(other) + + def __div__(self, other): + return int(self) / int(other) + + def __truediv__(self, other): + return int(self) / int(other) + + def __iadd__(self, other): + result = self.__add__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __isub__(self, other): + result = self.__sub__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __imul__(self, other): + result = self.__mul__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __idiv__(self, other): + result = self.__div__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __itruediv__(self, other): + result = self.__truediv__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ifloordiv__(self, other): + result = self.__floordiv__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __imod__(self, other): + result = self.__and__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ipow__(self, other): + result = self.__pow__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ipow__(self, other, modulo): + result = self.__pow__(self, other, modulo) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ilshift__(self, other): + result = self.__lshift__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __irshift__(self, other): + result = self.__rshift__(other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __iand__(self, other): + result = self.__and__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ixor__(self, other): + result = self.__xor__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __ior__(self, other): + result = self.__ior__(self, other) + self.sbvalue.SetValueFromCString (str(result)) + return result + + def __neg__(self): + return -int(self) + + def __pos__(self): + return +int(self) + + def __abs__(self): + return abs(int(self)) + + def __invert__(self): + return ~int(self) + + def __complex__(self): + return complex (int(self)) + + def __int__(self): + return self.sbvalue.GetValueAsSigned() + + def __long__(self): + return self.sbvalue.GetValueAsSigned() + + def __float__(self): + return float (self.sbvalue.GetValueAsSigned()) + + def __oct__(self): + return '0%o' % self.sbvalue.GetValueAsSigned() + + def __hex__(self): + return '0x%x' % self.sbvalue.GetValueAsSigned() + +%} + Modified: lldb/trunk/source/Target/ObjCLanguageRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ObjCLanguageRuntime.cpp?rev=149464&r1=149463&r2=149464&view=diff ============================================================================== --- lldb/trunk/source/Target/ObjCLanguageRuntime.cpp (original) +++ lldb/trunk/source/Target/ObjCLanguageRuntime.cpp Tue Jan 31 19:46:19 2012 @@ -1,4 +1,4 @@ -//===-- CPPLanguageRuntime.cpp -------------------------------------------------*- C++ -*-===// +//===-- ObjCLanguageRuntime.cpp ---------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // From johnny.chen at apple.com Tue Jan 31 19:49:50 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 01 Feb 2012 01:49:50 -0000 Subject: [Lldb-commits] [lldb] r149465 - in /lldb/trunk: source/Host/macosx/Symbols.cpp test/lldbtest.py test/plugins/builder_base.py test/plugins/builder_darwin.py test/plugins/builder_linux2.py test/warnings/ test/warnings/uuid/ test/warnings/uuid/Makefile test/warnings/uuid/TestUUIDMismatchWanring.py test/warnings/uuid/main.cpp.template Message-ID: <20120201014950.8B2FB2A6C12D@llvm.org> Author: johnny Date: Tue Jan 31 19:49:50 2012 New Revision: 149465 URL: http://llvm.org/viewvc/llvm-project?rev=149465&view=rev Log: lldb should warn when dSYM does not match the binary. o Symbols.cpp: Emit a warning message when dSYM does not match the binary. o warnings/uuid: Added regression test case. o lldbtest.py: Modified to allow test case writer to demand that the build command does not begin with a clean first; required to make TestUUIDMismatchWanring.py work. rdar://problem/10515708 Added: lldb/trunk/test/warnings/ lldb/trunk/test/warnings/uuid/ lldb/trunk/test/warnings/uuid/Makefile lldb/trunk/test/warnings/uuid/TestUUIDMismatchWanring.py lldb/trunk/test/warnings/uuid/main.cpp.template Modified: lldb/trunk/source/Host/macosx/Symbols.cpp lldb/trunk/test/lldbtest.py lldb/trunk/test/plugins/builder_base.py lldb/trunk/test/plugins/builder_darwin.py lldb/trunk/test/plugins/builder_linux2.py Modified: lldb/trunk/source/Host/macosx/Symbols.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Symbols.cpp?rev=149465&r1=149464&r2=149465&view=diff ============================================================================== --- lldb/trunk/source/Host/macosx/Symbols.cpp (original) +++ lldb/trunk/source/Host/macosx/Symbols.cpp Tue Jan 31 19:49:50 2012 @@ -24,6 +24,7 @@ #include "lldb/Core/Timer.h" #include "lldb/Core/UUID.h" #include "lldb/Host/Endian.h" +#include "lldb/Host/Host.h" #include "lldb/Utility/CleanUp.h" #include "Host/macosx/cfcpp/CFCBundle.h" #include "Host/macosx/cfcpp/CFCReleaser.h" @@ -116,7 +117,18 @@ if (cmd == LoadCommandUUID) { lldb_private::UUID file_uuid (data.GetData(&data_offset, 16), 16); - return file_uuid == *uuid; + if (file_uuid == *uuid) + return true; + + // Emit some warning messages since the UUIDs do not match! + char path_buf[PATH_MAX]; + path_buf[0] = '\0'; + const char *path = file_spec.GetPath(path_buf, PATH_MAX) ? path_buf + : file_spec.GetFilename().AsCString(); + Host::SystemLog (Host::eSystemLogWarning, + "warning: UUID mismatch detected between binary and:\n\t'%s'\n", + path); + return false; } data_offset = cmd_offset + cmd_size; } Modified: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=149465&r1=149464&r2=149465&view=diff ============================================================================== --- lldb/trunk/test/lldbtest.py (original) +++ lldb/trunk/test/lldbtest.py Tue Jan 31 19:49:50 2012 @@ -854,28 +854,28 @@ # Build methods supported through a plugin interface # ================================================== - def buildDefault(self, architecture=None, compiler=None, dictionary=None): + def buildDefault(self, architecture=None, compiler=None, dictionary=None, clean=True): """Platform specific way to build the default binaries.""" if lldb.skip_build_and_cleanup: return module = builder_module() - if not module.buildDefault(self, architecture, compiler, dictionary): + if not module.buildDefault(self, architecture, compiler, dictionary, clean): raise Exception("Don't know how to build default binary") - def buildDsym(self, architecture=None, compiler=None, dictionary=None): + def buildDsym(self, architecture=None, compiler=None, dictionary=None, clean=True): """Platform specific way to build binaries with dsym info.""" if lldb.skip_build_and_cleanup: return module = builder_module() - if not module.buildDsym(self, architecture, compiler, dictionary): + if not module.buildDsym(self, architecture, compiler, dictionary, clean): raise Exception("Don't know how to build binary with dsym") - def buildDwarf(self, architecture=None, compiler=None, dictionary=None): + def buildDwarf(self, architecture=None, compiler=None, dictionary=None, clean=True): """Platform specific way to build binaries with dwarf maps.""" if lldb.skip_build_and_cleanup: return module = builder_module() - if not module.buildDwarf(self, architecture, compiler, dictionary): + if not module.buildDwarf(self, architecture, compiler, dictionary, clean): raise Exception("Don't know how to build binary with dwarf") def cleanup(self, dictionary=None): Modified: lldb/trunk/test/plugins/builder_base.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/plugins/builder_base.py?rev=149465&r1=149464&r2=149465&view=diff ============================================================================== --- lldb/trunk/test/plugins/builder_base.py (original) +++ lldb/trunk/test/plugins/builder_base.py Tue Jan 31 19:49:50 2012 @@ -63,25 +63,38 @@ return " " + cmdline -def buildDefault(sender=None, architecture=None, compiler=None, dictionary=None): +def buildDefault(sender=None, architecture=None, compiler=None, dictionary=None, clean=True): """Build the binaries the default way.""" - lldbtest.system(["/bin/sh", "-c", - "make clean" + getCmdLine(dictionary) + "; make" - + getArchSpec(architecture) + getCCSpec(compiler) - + getCmdLine(dictionary)], - sender=sender) + if clean: + lldbtest.system(["/bin/sh", "-c", + "make clean" + getCmdLine(dictionary) + "; make" + + getArchSpec(architecture) + getCCSpec(compiler) + + getCmdLine(dictionary)], + sender=sender) + else: + lldbtest.system(["/bin/sh", "-c", + "make" + getArchSpec(architecture) + getCCSpec(compiler) + + getCmdLine(dictionary)], + sender=sender) # True signifies that we can handle building default. return True -def buildDwarf(sender=None, architecture=None, compiler=None, dictionary=None): +def buildDwarf(sender=None, architecture=None, compiler=None, dictionary=None, clean=True): """Build the binaries with dwarf debug info.""" - lldbtest.system(["/bin/sh", "-c", - "make clean" + getCmdLine(dictionary) - + "; make MAKE_DSYM=NO" - + getArchSpec(architecture) + getCCSpec(compiler) - + getCmdLine(dictionary)], - sender=sender) + if clean: + lldbtest.system(["/bin/sh", "-c", + "make clean" + getCmdLine(dictionary) + + "; make MAKE_DSYM=NO" + + getArchSpec(architecture) + getCCSpec(compiler) + + getCmdLine(dictionary)], + sender=sender) + else: + lldbtest.system(["/bin/sh", "-c", + "make MAKE_DSYM=NO" + + getArchSpec(architecture) + getCCSpec(compiler) + + getCmdLine(dictionary)], + sender=sender) # True signifies that we can handle building dwarf. return True Modified: lldb/trunk/test/plugins/builder_darwin.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/plugins/builder_darwin.py?rev=149465&r1=149464&r2=149465&view=diff ============================================================================== --- lldb/trunk/test/plugins/builder_darwin.py (original) +++ lldb/trunk/test/plugins/builder_darwin.py Tue Jan 31 19:49:50 2012 @@ -5,14 +5,21 @@ #print "Hello, darwin plugin!" -def buildDsym(sender=None, architecture=None, compiler=None, dictionary=None): +def buildDsym(sender=None, architecture=None, compiler=None, dictionary=None, clean=True): """Build the binaries with dsym debug info.""" - lldbtest.system(["/bin/sh", "-c", - "make clean" + getCmdLine(dictionary) - + "; make MAKE_DSYM=YES" - + getArchSpec(architecture) + getCCSpec(compiler) - + getCmdLine(dictionary)], - sender=sender) + if clean: + lldbtest.system(["/bin/sh", "-c", + "make clean" + getCmdLine(dictionary) + + "; make MAKE_DSYM=YES" + + getArchSpec(architecture) + getCCSpec(compiler) + + getCmdLine(dictionary)], + sender=sender) + else: + lldbtest.system(["/bin/sh", "-c", + "make MAKE_DSYM=YES" + + getArchSpec(architecture) + getCCSpec(compiler) + + getCmdLine(dictionary)], + sender=sender) # True signifies that we can handle building dsym. return True Modified: lldb/trunk/test/plugins/builder_linux2.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/plugins/builder_linux2.py?rev=149465&r1=149464&r2=149465&view=diff ============================================================================== --- lldb/trunk/test/plugins/builder_linux2.py (original) +++ lldb/trunk/test/plugins/builder_linux2.py Tue Jan 31 19:49:50 2012 @@ -1,4 +1,4 @@ from builder_base import * -def buildDsym(sender=None, architecture=None, compiler=None, dictionary=None): +def buildDsym(sender=None, architecture=None, compiler=None, dictionary=None, clean=True): return False Added: lldb/trunk/test/warnings/uuid/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/warnings/uuid/Makefile?rev=149465&view=auto ============================================================================== --- lldb/trunk/test/warnings/uuid/Makefile (added) +++ lldb/trunk/test/warnings/uuid/Makefile Tue Jan 31 19:49:50 2012 @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/test/warnings/uuid/TestUUIDMismatchWanring.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/warnings/uuid/TestUUIDMismatchWanring.py?rev=149465&view=auto ============================================================================== --- lldb/trunk/test/warnings/uuid/TestUUIDMismatchWanring.py (added) +++ lldb/trunk/test/warnings/uuid/TestUUIDMismatchWanring.py Tue Jan 31 19:49:50 2012 @@ -0,0 +1,113 @@ +"""Test that the 'warning: UUID mismatch detected ...' message is emitted.""" + +import os, time +import unittest2 +import lldb +import pexpect +from lldbtest import * + + at unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") +class UUIDMismatchWarningCase(TestBase): + + mydir = os.path.join("warnings", "uuid") + + @classmethod + def classCleanup(cls): + """Cleanup the test byproducts.""" + system(["/bin/sh", "-c", "rm -f child_send.txt"]) + system(["/bin/sh", "-c", "rm -f child_read.txt"]) + + def setUp(self): + TestBase.setUp(self) + self.template = 'main.cpp.template' + self.source = 'main.cpp' + self.teardown_hook_added = False + + def test_uuid_mismatch_warning(self): + """Test that the 'warning: UUID mismatch detected ...' message is emitted.""" + + # Call the program generator to produce main.cpp, version 1. + self.generate_main_cpp(version=1) + self.line_to_break = line_number(self.source, '// Set breakpoint here.') + self.buildDsym(clean=True) + + # Insert some delay and then call the program generator to produce main.cpp, version 2. + time.sleep(5) + self.generate_main_cpp(version=101) + # Now call make again, but this time don't generate the dSYM. + self.buildDwarf(clean=False) + + self.exe_name = 'a.out' + self.check_executable_and_dsym(self.exe_name) + + def generate_main_cpp(self, version=0): + """Generate main.cpp from main.cpp.template.""" + temp = os.path.join(os.getcwd(), self.template) + with open(temp, 'r') as f: + content = f.read() + + new_content = content.replace('%ADD_EXTRA_CODE%', + 'printf("This is version %d\\n");' % version) + src = os.path.join(os.getcwd(), self.source) + with open(src, 'w') as f: + f.write(new_content) + + # The main.cpp has been generated, add a teardown hook to remove it. + if not self.teardown_hook_added: + self.addTearDownHook(lambda: os.remove(src)) + self.teardown_hook_added = True + + def check_executable_and_dsym(self, exe_name): + """Sanity check executable compiled from the auto-generated program.""" + + # The default lldb prompt. + prompt = "(lldb) " + + # So that the child gets torn down after the test. + self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption)) + child = self.child + # Turn on logging for input/output to/from the child. + with open('child_send.txt', 'w') as f_send: + with open('child_read.txt', 'w') as f_read: + child.logfile_send = f_send + child.logfile_read = f_read + + child.expect_exact(prompt) + child.setecho(True) + + # Execute the file command, followed by a breakpoint set, the + # UUID mismatch warning should be generated by then. + + child.sendline("file %s" % exe_name) + child.expect_exact(prompt) + child.sendline("breakpoint set -f %s -l %d" % (self.source, self.line_to_break)) + child.expect_exact(prompt) + child.sendline("run") + child.expect_exact(prompt) + + # Now that the necessary logging is done, restore logfile to None to + # stop further logging. + child.logfile_send = None + child.logfile_read = None + + with open('child_send.txt', 'r') as fs: + if self.TraceOn(): + print "\n\nContents of child_send.txt:" + print fs.read() + with open('child_read.txt', 'r') as fr: + from_child = fr.read() + if self.TraceOn(): + print "\n\nContents of child_read.txt:" + print from_child + + # Test that str_input completes to our patterns. + # If each pattern matches from_child, the completion mechanism works! + self.expect(from_child, msg="UUID mismatch expected!", exe=False, + substrs = ['warning: UUID mismatch detected']) + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/warnings/uuid/main.cpp.template URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/warnings/uuid/main.cpp.template?rev=149465&view=auto ============================================================================== --- lldb/trunk/test/warnings/uuid/main.cpp.template (added) +++ lldb/trunk/test/warnings/uuid/main.cpp.template Tue Jan 31 19:49:50 2012 @@ -0,0 +1,19 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include + +int +main(int argc, char const *argv[]) +{ + int my_int = argc + 3; + printf("Hello UUID Mismatch: %d\n", my_int); // Set breakpoint here. + %ADD_EXTRA_CODE% + return 0; +} From gclayton at apple.com Tue Jan 31 20:30:27 2012 From: gclayton at apple.com (Greg Clayton) Date: Wed, 01 Feb 2012 02:30:27 -0000 Subject: [Lldb-commits] [lldb] r149466 - in /lldb/trunk/scripts/Python: interface/SBThread.i python-extensions.swig Message-ID: <20120201023027.78BFC2A6C12C@llvm.org> Author: gclayton Date: Tue Jan 31 20:30:27 2012 New Revision: 149466 URL: http://llvm.org/viewvc/llvm-project?rev=149466&view=rev Log: Added a new convenience property on lldb.SBThread names "frames" which always returns a complete list of all lldb.SBFrame objects: (lldb) script >>> frames = lldb.thread.frames >>> for frame in frames: ... print frame Also changed all of the "__repr__" methods to strip any trailing newline characters so we don't end up with entra newlines. Modified: lldb/trunk/scripts/Python/interface/SBThread.i lldb/trunk/scripts/Python/python-extensions.swig Modified: lldb/trunk/scripts/Python/interface/SBThread.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBThread.i?rev=149466&r1=149465&r2=149466&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBThread.i (original) +++ lldb/trunk/scripts/Python/interface/SBThread.i Tue Jan 31 20:30:27 2012 @@ -175,6 +175,13 @@ GetDescription (lldb::SBStream &description) const; %pythoncode %{ + def get_thread_frames(self): + frames = [] + for frame in self: + frames.append(frame) + return frames + + __swig_getmethods__["id"] = GetThreadID if _newclass: x = property(GetThreadID, None) @@ -190,6 +197,9 @@ __swig_getmethods__["num_frames"] = GetNumFrames if _newclass: x = property(GetNumFrames, None) + __swig_getmethods__["frames"] = get_thread_frames + if _newclass: x = property(get_thread_frames, None) + __swig_getmethods__["name"] = GetName if _newclass: x = property(GetName, None) Modified: lldb/trunk/scripts/Python/python-extensions.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=149466&r1=149465&r2=149466&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-extensions.swig (original) +++ lldb/trunk/scripts/Python/python-extensions.swig Tue Jan 31 20:30:27 2012 @@ -3,182 +3,338 @@ PyObject *lldb::SBAddress::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBBlock { PyObject *lldb::SBBlock::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBBreakpoint { PyObject *lldb::SBBreakpoint::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBBreakpointLocation { PyObject *lldb::SBBreakpointLocation::__repr__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelFull); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBCommandReturnObject { PyObject *lldb::SBCommandReturnObject::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBCompileUnit { PyObject *lldb::SBCompileUnit::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBData { PyObject *lldb::SBData::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBDebugger { PyObject *lldb::SBDebugger::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBError { PyObject *lldb::SBError::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBFileSpec { PyObject *lldb::SBFileSpec::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBFrame { PyObject *lldb::SBFrame::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBFunction { PyObject *lldb::SBFunction::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBInstruction { PyObject *lldb::SBInstruction::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBInstructionList { PyObject *lldb::SBInstructionList::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBLineEntry { PyObject *lldb::SBLineEntry::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBModule { PyObject *lldb::SBModule::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBProcess { PyObject *lldb::SBProcess::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBSection { PyObject *lldb::SBSection::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBSymbol { PyObject *lldb::SBSymbol::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBSymbolContext { PyObject *lldb::SBSymbolContext::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBTarget { PyObject *lldb::SBTarget::__repr__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelBrief); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBType { PyObject *lldb::SBType::__repr__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelBrief); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBTypeMember { PyObject *lldb::SBTypeMember::__repr__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelBrief); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBThread { PyObject *lldb::SBThread::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBValue { PyObject *lldb::SBValue::__repr__ (){ lldb::SBStream description; $self->GetDescription (description); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } %extend lldb::SBWatchpoint { PyObject *lldb::SBWatchpoint::__repr__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelVerbose); - return PyString_FromString (description.GetData()); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; } } From gclayton at apple.com Wed Feb 1 02:09:33 2012 From: gclayton at apple.com (Greg Clayton) Date: Wed, 01 Feb 2012 08:09:33 -0000 Subject: [Lldb-commits] [lldb] r149489 - in /lldb/trunk: scripts/ scripts/Python/interface/ source/Interpreter/ source/Symbol/ Message-ID: <20120201080933.A71C72A6C12C@llvm.org> Author: gclayton Date: Wed Feb 1 02:09:32 2012 New Revision: 149489 URL: http://llvm.org/viewvc/llvm-project?rev=149489&view=rev Log: Added many more python convenience accessors: You can now access a frame in a thread using: lldb.SBThread.frame[int] -> lldb.SBFrame object for a frame in a thread Where "int" is an integer index. You can also access a list object with all of the frames using: lldb.SBThread.frames => list() of lldb.SBFrame objects All SB objects that give out SBAddress objects have properties named "addr" lldb.SBInstructionList now has the following convenience accessors for len() and instruction access using an index: insts = lldb.frame.function.instructions for idx in range(len(insts)): print insts[idx] Instruction lists can also lookup an isntruction using a lldb.SBAddress as the key: pc_inst = lldb.frame.function.instructions[lldb.frame.addr] lldb.SBProcess now exposes: lldb.SBProcess.is_alive => BOOL Check if a process is exists and is alive lldb.SBProcess.is_running => BOOL check if a process is running (or stepping): lldb.SBProcess.is_running => BOOL check if a process is currently stopped or crashed: lldb.SBProcess.thread[int] => lldb.SBThreads for a given "int" zero based index lldb.SBProcess.threads => list() containing all lldb.SBThread objects in a process SBInstruction now exposes: lldb.SBInstruction.mnemonic => python string for instruction mnemonic lldb.SBInstruction.operands => python string for instruction operands lldb.SBInstruction.command => python string for instruction comment SBModule now exposes: lldb.SBModule.uuid => uuid.UUID(), an UUID object from the "uuid" python module lldb.SBModule.symbol[int] => lldb.Symbol, lookup symbol by zero based index lldb.SBModule.symbol[str] => list() of lldb.Symbol objects that match "str" lldb.SBModule.symbol[re] => list() of lldb.Symbol objecxts that match the regex lldb.SBModule.symbols => list() of all symbols in a module SBAddress objects can now access the current load address with the "lldb.SBAddress.load_addr" property. The current "lldb.target" will be used to try and resolve the load address. Load addresses can also be set using this accessor: addr = lldb.SBAddress() addd.load_addr = 0x123023 Then you can check the section and offset to see if the address got resolved. SBTarget now exposes: lldb.SBTarget.module[int] => lldb.SBModule from zero based module index lldb.SBTarget.module[str] => lldb.SBModule by basename or fullpath or uuid string lldb.SBTarget.module[uuid.UUID()] => lldb.SBModule whose UUID matches lldb.SBTarget.module[re] => list() of lldb.SBModule objects that match the regex lldb.SBTarget.modules => list() of all lldb.SBModule objects in the target SBSymbol now exposes: lldb.SBSymbol.name => python string for demangled symbol name lldb.SBSymbol.mangled => python string for mangled symbol name or None if there is none lldb.SBSymbol.type => lldb.eSymbolType enum value lldb.SBSymbol.addr => SBAddress object that represents the start address for this symbol (if there is one) lldb.SBSymbol.end_addr => SBAddress for the end address of the symbol (if there is one) lldb.SBSymbol.prologue_size => pythin int containing The size of the prologue in bytes lldb.SBSymbol.instructions => SBInstructionList containing all instructions for this symbol SBFunction now also has these new properties in addition to what is already has: lldb.SBFunction.addr => SBAddress object that represents the start address for this function lldb.SBFunction.end_addr => SBAddress for the end address of the function lldb.SBFunction.instructions => SBInstructionList containing all instructions for this function SBFrame now exposes the SBAddress for the frame: lldb.SBFrame.addr => SBAddress which is the section offset address for the current frame PC These are all in addition to what was already added. Documentation and website updates coming soon. Modified: lldb/trunk/scripts/Python/interface/SBAddress.i lldb/trunk/scripts/Python/interface/SBFileSpec.i lldb/trunk/scripts/Python/interface/SBFrame.i lldb/trunk/scripts/Python/interface/SBFunction.i lldb/trunk/scripts/Python/interface/SBInstruction.i lldb/trunk/scripts/Python/interface/SBInstructionList.i lldb/trunk/scripts/Python/interface/SBLineEntry.i lldb/trunk/scripts/Python/interface/SBModule.i lldb/trunk/scripts/Python/interface/SBProcess.i lldb/trunk/scripts/Python/interface/SBSymbol.i lldb/trunk/scripts/Python/interface/SBTarget.i lldb/trunk/scripts/Python/interface/SBThread.i lldb/trunk/scripts/lldb.swig lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp lldb/trunk/source/Symbol/Symbol.cpp Modified: lldb/trunk/scripts/Python/interface/SBAddress.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBAddress.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBAddress.i (original) +++ lldb/trunk/scripts/Python/interface/SBAddress.i Wed Feb 1 02:09:32 2012 @@ -129,6 +129,28 @@ GetLineEntry (); %pythoncode %{ + def __get_load_addr_property__ (self): + '''Get the load address for a lldb.SBAddress using the current target.''' + return self.GetLoadAddress (target) + + def __set_load_addr_property__ (self, load_addr): + '''Set the load address for a lldb.SBAddress using the current target.''' + return self.SetLoadAddress (load_addr, target) + + def __int__(self): + '''Convert an address to a load address if there is a process and that + process is alive, or to a file address otherwise.''' + if process.is_alive: + return self.GetLoadAddress (target) + else: + return self.GetFileAddress () + + def __oct__(self): + return '%o' % int(self) + + def __hex__(self): + return '0x%x' % int(self) + __swig_getmethods__["module"] = GetModule if _newclass: x = property(GetModule, None) @@ -156,6 +178,10 @@ __swig_getmethods__["file_addr"] = GetFileAddress if _newclass: x = property(GetFileAddress, None) + __swig_getmethods__["load_addr"] = __get_load_addr_property__ + __swig_setmethods__["load_addr"] = __set_load_addr_property__ + if _newclass: x = property(__get_load_addr_property__, __set_load_addr_property__) + %} }; Modified: lldb/trunk/scripts/Python/interface/SBFileSpec.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFileSpec.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBFileSpec.i (original) +++ lldb/trunk/scripts/Python/interface/SBFileSpec.i Wed Feb 1 02:09:32 2012 @@ -68,6 +68,20 @@ GetDescription (lldb::SBStream &description) const; %pythoncode %{ + def __get_fullpath__(self): + spec_dir = self.GetDirectory() + spec_file = self.GetFilename() + if spec_dir and spec_file: + return '%s/%s' % (spec_dir, spec_file) + elif spec_dir: + return spec_dir + elif spec_file: + return spec_file + return None + + __swig_getmethods__["fullpath"] = __get_fullpath__ + if _newclass: x = property(__get_fullpath__, None) + __swig_getmethods__["basename"] = GetFilename if _newclass: x = property(GetFilename, None) Modified: lldb/trunk/scripts/Python/interface/SBFrame.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFrame.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBFrame.i (original) +++ lldb/trunk/scripts/Python/interface/SBFrame.i Wed Feb 1 02:09:32 2012 @@ -223,6 +223,9 @@ __swig_setmethods__["pc"] = SetPC if _newclass: x = property(GetPC, SetPC) + __swig_getmethods__["addr"] = GetPCAddress + if _newclass: x = property(GetPCAddress, None) + __swig_getmethods__["fp"] = GetFP if _newclass: x = property(GetFP, None) Modified: lldb/trunk/scripts/Python/interface/SBFunction.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFunction.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBFunction.i (original) +++ lldb/trunk/scripts/Python/interface/SBFunction.i Wed Feb 1 02:09:32 2012 @@ -78,13 +78,16 @@ GetDescription (lldb::SBStream &description); %pythoncode %{ + def get_instructions_from_current_target (self): + return self.GetInstructions (target) + __swig_getmethods__["name"] = GetName if _newclass: x = property(GetName, None) __swig_getmethods__["mangled"] = GetMangledName if _newclass: x = property(GetMangledName, None) - __swig_getmethods__["start_addr"] = GetStartAddress + __swig_getmethods__["addr"] = GetStartAddress if _newclass: x = property(GetStartAddress, None) __swig_getmethods__["end_addr"] = GetEndAddress @@ -92,7 +95,10 @@ __swig_getmethods__["prologue_size"] = GetPrologueByteSize if _newclass: x = property(GetPrologueByteSize, None) - + + __swig_getmethods__["instructions"] = get_instructions_from_current_target + if _newclass: x = property(get_instructions_from_current_target, None) + %} }; Modified: lldb/trunk/scripts/Python/interface/SBInstruction.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBInstruction.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBInstruction.i (original) +++ lldb/trunk/scripts/Python/interface/SBInstruction.i Wed Feb 1 02:09:32 2012 @@ -64,6 +64,26 @@ TestEmulation (lldb::SBStream &output_stream, const char *test_file); %pythoncode %{ + def __mnemonic_property__ (self): + return self.GetMnemonic (target) + def __operands_property__ (self): + return self.GetOperands (target) + def __comment_property__ (self): + return self.GetComment (target) + def __file_addr_property__ (self): + return self.GetAddress ().GetFileAddress() + def __load_adrr_property__ (self): + return self.GetComment (target) + + __swig_getmethods__["mnemonic"] = __mnemonic_property__ + if _newclass: x = property(__mnemonic_property__, None) + + __swig_getmethods__["operands"] = __operands_property__ + if _newclass: x = property(__operands_property__, None) + + __swig_getmethods__["comment"] = __comment_property__ + if _newclass: x = property(__comment_property__, None) + __swig_getmethods__["addr"] = GetAddress if _newclass: x = property(GetAddress, None) Modified: lldb/trunk/scripts/Python/interface/SBInstructionList.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBInstructionList.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBInstructionList.i (original) +++ lldb/trunk/scripts/Python/interface/SBInstructionList.i Wed Feb 1 02:09:32 2012 @@ -58,6 +58,34 @@ bool DumpEmulationForAllInstructions (const char *triple); + + %pythoncode %{ + def __len__(self): + '''Access len of the instruction list.''' + return self.GetSize(); + + def __getitem__(self, key): + '''Access instructions by integer index.''' + if type(key) is int: + # Find an instruction by index + if key < len(self): + return self.GetInstructionAtIndex(key) + elif type(key) is SBAddress: + # Find an instruction using a lldb.SBAddress object + lookup_file_addr = key.file_addr + closest_inst = None + for idx in range(self.GetSize()): + inst = self.GetInstructionAtIndex(idx) + inst_file_addr = inst.addr.file_addr + if inst_file_addr == lookup_file_addr: + return inst + elif inst_file_addr > lookup_file_addr: + return closest_inst + else: + closest_inst = inst + return None + %} + }; } // namespace lldb Modified: lldb/trunk/scripts/Python/interface/SBLineEntry.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBLineEntry.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBLineEntry.i (original) +++ lldb/trunk/scripts/Python/interface/SBLineEntry.i Wed Feb 1 02:09:32 2012 @@ -87,7 +87,7 @@ __swig_getmethods__["column"] = GetColumn if _newclass: x = property(GetColumn, None) - __swig_getmethods__["start_addr"] = GetStartAddress + __swig_getmethods__["addr"] = GetStartAddress if _newclass: x = property(GetStartAddress, None) __swig_getmethods__["end_addr"] = GetEndAddress Modified: lldb/trunk/scripts/Python/interface/SBModule.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBModule.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBModule.i (original) +++ lldb/trunk/scripts/Python/interface/SBModule.i Wed Feb 1 02:09:32 2012 @@ -247,15 +247,82 @@ GetTriple (); %pythoncode %{ + class symbols_access(object): + re_type = type(re.compile('.')) + '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' + def __init__(self, sbmodule): + self.sbmodule = sbmodule + + def __len__(self): + if self.sbmodule: + return self.sbmodule.GetNumSymbols() + return 0 + + def __getitem__(self, key): + count = self.sbmodule.GetNumSymbols() + if type(key) is int: + if key < count: + return self.sbmodule.GetSymbolAtIndex(key) + elif type(key) is str: + matches = [] + for idx in range(count): + symbol = self.sbmodule.GetSymbolAtIndex(idx) + if symbol.name == key or symbol.mangled == key: + matches.append(symbol) + if len(matches): + return matches + elif isinstance(key, self.re_type): + matches = [] + for idx in range(count): + symbol = self.sbmodule.GetSymbolAtIndex(idx) + added = False + name = symbol.name + if name: + re_match = key.search(name) + if re_match: + matches.append(symbol) + added = True + if not added: + mangled = symbol.mangled + if mangled: + re_match = key.search(mangled) + if re_match: + matches.append(symbol) + if len(matches): + return matches + else: + print "error: unsupported item type: %s" % type(key) + return None + + def get_symbols_access_object(self): + '''An accessor function that retuns a symbols_access() object which allows lazy module array access.''' + return self.symbols_access (self) + + def get_symbols_array(self): + '''An accessor function that retuns an array object that contains all modules in this target object.''' + symbols = [] + for idx in range(self.GetNumSymbols()): + symbols.append(self.GetSymbolAtIndex(idx)) + return symbols + + __swig_getmethods__["symbols"] = get_symbols_array + if _newclass: x = property(get_symbols_array, None) + + __swig_getmethods__["symbol"] = get_symbols_access_object + if _newclass: x = property(get_symbols_access_object, None) + + def get_uuid(self): + return uuid.UUID (self.GetUUIDString()) + + __swig_getmethods__["uuid"] = get_uuid + if _newclass: x = property(get_uuid, None) + __swig_getmethods__["file"] = GetFileSpec if _newclass: x = property(GetFileSpec, None) __swig_getmethods__["platform_file"] = GetPlatformFileSpec if _newclass: x = property(GetPlatformFileSpec, None) - __swig_getmethods__["uuid"] = GetUUIDString - if _newclass: x = property(GetUUIDString, None) - __swig_getmethods__["byte_order"] = GetByteOrder if _newclass: x = property(GetByteOrder, None) Modified: lldb/trunk/scripts/Python/interface/SBProcess.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBProcess.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBProcess.i (original) +++ lldb/trunk/scripts/Python/interface/SBProcess.i Wed Feb 1 02:09:32 2012 @@ -282,6 +282,73 @@ UnloadImage (uint32_t image_token); %pythoncode %{ + def __get_is_alive__(self): + '''Returns "True" if the process is currently alive, "False" otherwise''' + s = self.GetState() + if (s == eStateAttaching or + s == eStateLaunching or + s == eStateStopped or + s == eStateRunning or + s == eStateStepping or + s == eStateCrashed or + s == eStateSuspended): + return True + return False + + def __get_is_running__(self): + '''Returns "True" if the process is currently running, "False" otherwise''' + state = self.GetState() + if state == eStateRunning or state == eStateStepping: + return True + return False + + def __get_is_running__(self): + '''Returns "True" if the process is currently stopped, "False" otherwise''' + state = self.GetState() + if state == eStateStopped or state == eStateCrashed or state == eStateSuspended: + return True + return False + + class thread_array_access(object): + '''A helper object that will lazily hand out thread for a process when supplied an index.''' + def __init__(self, sbprocess): + self.sbprocess = sbprocess + + def __len__(self): + if self.sbprocess: return self.sbprocess.GetNumThreads() + return 0 + + def __getitem__(self, key): + if type(key) is int and key < len(self): + return self.sbprocess.GetThreadAtIndex(key) + return None + + def get_thread_array_access_object(self): + '''An accessor function that retuns a thread_array_access() object which allows lazy thread array access.''' + return self.thread_array_access (self) + + def get_process_thread_list(self): + '''An accessor function that retuns an array object that contains all threads in this process object.''' + threads = [] + for idx in range(self.GetNumThreads()): + threads.append(GetThreadAtIndex(idx)) + return threads + + __swig_getmethods__["threads"] = get_process_thread_list + if _newclass: x = property(get_process_thread_list, None) + + __swig_getmethods__["thread"] = get_thread_array_access_object + if _newclass: x = property(get_thread_array_access_object, None) + + __swig_getmethods__["is_alive"] = __get_is_alive__ + if _newclass: x = property(__get_is_alive__, None) + + __swig_getmethods__["is_running"] = __get_is_running__ + if _newclass: x = property(__get_is_running__, None) + + __swig_getmethods__["is_stopped"] = __get_is_running__ + if _newclass: x = property(__get_is_running__, None) + __swig_getmethods__["id"] = GetProcessID if _newclass: x = property(GetProcessID, None) Modified: lldb/trunk/scripts/Python/interface/SBSymbol.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBSymbol.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBSymbol.i (original) +++ lldb/trunk/scripts/Python/interface/SBSymbol.i Wed Feb 1 02:09:32 2012 @@ -52,6 +52,34 @@ bool GetDescription (lldb::SBStream &description); + + %pythoncode %{ + def get_instructions_from_current_target (self): + return self.GetInstructions (target) + + __swig_getmethods__["name"] = GetName + if _newclass: x = property(GetName, None) + + __swig_getmethods__["mangled"] = GetMangledName + if _newclass: x = property(GetMangledName, None) + + __swig_getmethods__["type"] = GetType + if _newclass: x = property(GetType, None) + + __swig_getmethods__["addr"] = GetStartAddress + if _newclass: x = property(GetStartAddress, None) + + __swig_getmethods__["end_addr"] = GetEndAddress + if _newclass: x = property(GetEndAddress, None) + + __swig_getmethods__["prologue_size"] = GetPrologueByteSize + if _newclass: x = property(GetPrologueByteSize, None) + + __swig_getmethods__["instructions"] = get_instructions_from_current_target + if _newclass: x = property(get_instructions_from_current_target, None) + + %} + }; } // namespace lldb Modified: lldb/trunk/scripts/Python/interface/SBTarget.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBTarget.i (original) +++ lldb/trunk/scripts/Python/interface/SBTarget.i Wed Feb 1 02:09:32 2012 @@ -487,6 +487,73 @@ GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); %pythoncode %{ + class modules_access(object): + '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' + def __init__(self, sbtarget): + self.sbtarget = sbtarget + + def __len__(self): + if self.sbtarget: + return self.sbtarget.GetNumModules() + return 0 + + def __getitem__(self, key): + num_modules = self.sbtarget.GetNumModules() + if type(key) is int: + if key < num_modules: + return self.sbtarget.GetModuleAtIndex(key) + elif type(key) is str: + if key.find('/') == -1: + for idx in range(num_modules): + module = self.sbtarget.GetModuleAtIndex(idx) + if module.file.basename == key: + return module + else: + for idx in range(num_modules): + module = self.sbtarget.GetModuleAtIndex(idx) + if module.file.fullpath == key: + return module + # See if the string is a UUID + the_uuid = uuid.UUID(key) + if the_uuid: + for idx in range(num_modules): + module = self.sbtarget.GetModuleAtIndex(idx) + if module.uuid == the_uuid: + return module + elif type(key) is uuid.UUID: + for idx in range(num_modules): + module = self.sbtarget.GetModuleAtIndex(idx) + if module.uuid == key: + return module + elif type(key) is re.SRE_Pattern: + matching_modules = [] + for idx in range(num_modules): + module = self.sbtarget.GetModuleAtIndex(idx) + re_match = key.search(module.path.fullpath) + if re_match: + matching_modules.append(module) + return matching_modules + else: + print "error: unsupported item type: %s" % type(key) + return None + + def get_modules_access_object(self): + '''An accessor function that retuns a modules_access() object which allows lazy module array access.''' + return self.modules_access (self) + + def get_modules_array(self): + '''An accessor function that retuns an array object that contains all modules in this target object.''' + modules = [] + for idx in range(self.GetNumModules()): + modules.append(self.GetModuleAtIndex(idx)) + return modules + + __swig_getmethods__["modules"] = get_modules_array + if _newclass: x = property(get_modules_array, None) + + __swig_getmethods__["module"] = get_modules_access_object + if _newclass: x = property(get_modules_access_object, None) + __swig_getmethods__["process"] = GetProcess if _newclass: x = property(GetProcess, None) Modified: lldb/trunk/scripts/Python/interface/SBThread.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBThread.i?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBThread.i (original) +++ lldb/trunk/scripts/Python/interface/SBThread.i Wed Feb 1 02:09:32 2012 @@ -175,13 +175,32 @@ GetDescription (lldb::SBStream &description) const; %pythoncode %{ + class frame_array_access(object): + '''A helper object that will lazily hand out frames for a thread when supplied an index.''' + def __init__(self, sbthread): + self.sbthread = sbthread + + def __len__(self): + if self.sbthread: + return self.sbthread.GetNumFrames() + return 0 + + def __getitem__(self, key): + if type(key) is int and key < self.sbthread.GetNumFrames(): + return self.sbthread.GetFrameAtIndex(key) + return None + + def get_frame_array_access_object(self): + '''An accessor function that retuns a frame_array_access() object which allows lazy frame array access.''' + return self.frame_array_access (self) + def get_thread_frames(self): + '''An accessor function that retuns an array object that contains all frames in this thread object.''' frames = [] for frame in self: frames.append(frame) return frames - - + __swig_getmethods__["id"] = GetThreadID if _newclass: x = property(GetThreadID, None) @@ -200,6 +219,9 @@ __swig_getmethods__["frames"] = get_thread_frames if _newclass: x = property(get_thread_frames, None) + __swig_getmethods__["frame"] = get_frame_array_access_object + if _newclass: x = property(get_frame_array_access_object, None) + __swig_getmethods__["name"] = GetName if _newclass: x = property(GetName, None) Modified: lldb/trunk/scripts/lldb.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/scripts/lldb.swig (original) +++ lldb/trunk/scripts/lldb.swig Wed Feb 1 02:09:32 2012 @@ -37,6 +37,11 @@ // Parameter types will be used in the autodoc string. %feature("autodoc", "1"); +%pythoncode%{ +import uuid +import re +import os +%} %include "./Python/python-typemaps.swig" /* The liblldb header files to be included. */ Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Feb 1 02:09:32 2012 @@ -208,8 +208,6 @@ PyRun_SimpleString (run_string.GetData()); run_string.Clear(); - run_string.Printf ("run_one_line (%s, 'import sys')", m_dictionary_name.c_str()); - PyRun_SimpleString (run_string.GetData()); // Importing 'lldb' module calls SBDebugger::Initialize, which calls Debugger::Initialize, which increments a // global debugger ref-count; therefore we need to check the ref-count before and after importing lldb, and if the @@ -220,37 +218,22 @@ // which case the code inside it, including the call to SBDebugger::Initialize(), does not get executed. int old_count = Debugger::TestDebuggerRefCount(); + - run_string.Clear(); - run_string.Printf ("run_one_line (%s, 'import lldb')", m_dictionary_name.c_str()); + run_string.Printf ("run_one_line (%s, 'import copy, os, re, sys, uuid, lldb, gnu_libstdcpp, objc')", m_dictionary_name.c_str()); PyRun_SimpleString (run_string.GetData()); + int new_count = Debugger::TestDebuggerRefCount(); if (new_count > old_count) Debugger::Terminate(); run_string.Clear(); - run_string.Printf ("run_one_line (%s, 'import copy')", m_dictionary_name.c_str()); - PyRun_SimpleString (run_string.GetData()); - - run_string.Clear(); - run_string.Printf ("run_one_line (%s, 'import os')", m_dictionary_name.c_str()); - PyRun_SimpleString (run_string.GetData()); - - run_string.Clear(); run_string.Printf ("run_one_line (%s, 'lldb.debugger_unique_id = %llu')", m_dictionary_name.c_str(), interpreter.GetDebugger().GetID()); PyRun_SimpleString (run_string.GetData()); - run_string.Clear(); - run_string.Printf ("run_one_line (%s, 'import gnu_libstdcpp')", m_dictionary_name.c_str()); - PyRun_SimpleString (run_string.GetData()); - - run_string.Clear(); - run_string.Printf ("run_one_line (%s, 'import objc')", m_dictionary_name.c_str()); - PyRun_SimpleString (run_string.GetData()); - if (m_dbg_stdout != NULL) { m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush); Modified: lldb/trunk/source/Symbol/Symbol.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=149489&r1=149488&r2=149489&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Symbol.cpp (original) +++ lldb/trunk/source/Symbol/Symbol.cpp Wed Feb 1 02:09:32 2012 @@ -183,7 +183,7 @@ void Symbol::GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target) const { - *s << "id = " << (const UserID&)*this << ", name = \"" << m_mangled.GetName() << '"'; + s->Printf("uid={%6u}", m_uid); const Section *section = m_addr_range.GetBaseAddress().GetSection(); if (section != NULL) @@ -211,6 +211,11 @@ else s->Printf (", value = 0x%16.16llx", m_addr_range.GetBaseAddress().GetOffset()); } + if (m_mangled.GetDemangledName()) + s->Printf(", name=\"%s\"", m_mangled.GetDemangledName().AsCString()); + if (m_mangled.GetMangledName()) + s->Printf(", mangled=\"%s\"", m_mangled.GetMangledName().AsCString()); + } void From johnny.chen at apple.com Wed Feb 1 12:26:25 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 01 Feb 2012 18:26:25 -0000 Subject: [Lldb-commits] [lldb] r149519 - /lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py Message-ID: <20120201182625.5CD8F2A6C12C@llvm.org> Author: johnny Date: Wed Feb 1 12:26:25 2012 New Revision: 149519 URL: http://llvm.org/viewvc/llvm-project?rev=149519&view=rev Log: Add @expectedFailure decorators. Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py?rev=149519&r1=149518&r2=149519&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py Wed Feb 1 12:26:25 2012 @@ -12,7 +12,7 @@ mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "map") #rdar://problem/10334911 - #@unittest2.expectedFailure + @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_with_dsym_and_run_command(self): """Test data formatter commands.""" @@ -20,7 +20,7 @@ self.data_formatter_commands() #rdar://problem/10334911 - #@unittest2.expectedFailure + @unittest2.expectedFailure def test_with_dwarf_and_run_command(self): """Test data formatter commands.""" self.buildDwarf() From johnny.chen at apple.com Wed Feb 1 13:05:21 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 01 Feb 2012 19:05:21 -0000 Subject: [Lldb-commits] [lldb] r149523 - in /lldb/trunk: include/lldb/Breakpoint/BreakpointLocation.h source/Breakpoint/BreakpointLocation.cpp Message-ID: <20120201190521.2C9172A6C12C@llvm.org> Author: johnny Date: Wed Feb 1 13:05:20 2012 New Revision: 149523 URL: http://llvm.org/viewvc/llvm-project?rev=149523&view=rev Log: Add const-ness to BreakpointLocation::IsEnabled(). Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h?rev=149523&r1=149522&r2=149523&view=diff ============================================================================== --- lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h (original) +++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h Wed Feb 1 13:05:20 2012 @@ -111,7 +111,7 @@ /// \b true if the breakpoint is enabled, \b false if disabled. //------------------------------------------------------------------ bool - IsEnabled (); + IsEnabled () const; //------------------------------------------------------------------ /// Return the current Ignore Count. Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=149523&r1=149522&r2=149523&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Wed Feb 1 13:05:20 2012 @@ -70,7 +70,7 @@ } bool -BreakpointLocation::IsEnabled () +BreakpointLocation::IsEnabled () const { if (!m_owner.IsEnabled()) return false; From johnny.chen at apple.com Wed Feb 1 13:35:56 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 01 Feb 2012 19:35:56 -0000 Subject: [Lldb-commits] [lldb] r149529 - /lldb/trunk/test/functionalities/target_command/TestTargetCommand.py Message-ID: <20120201193556.0F5302A6C12C@llvm.org> Author: johnny Date: Wed Feb 1 13:35:55 2012 New Revision: 149529 URL: http://llvm.org/viewvc/llvm-project?rev=149529&view=rev Log: Fix indentation. Modified: lldb/trunk/test/functionalities/target_command/TestTargetCommand.py Modified: lldb/trunk/test/functionalities/target_command/TestTargetCommand.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/target_command/TestTargetCommand.py?rev=149529&r1=149528&r2=149529&view=diff ============================================================================== --- lldb/trunk/test/functionalities/target_command/TestTargetCommand.py (original) +++ lldb/trunk/test/functionalities/target_command/TestTargetCommand.py Wed Feb 1 13:35:55 2012 @@ -178,7 +178,7 @@ self.runCmd("b main") self.runCmd("run") - # New feature: you don't need to specify the variable(s) to 'target vaiable'. + # New feature: you don't need to specify the variable(s) to 'target vaiable'. # It will find all the global and static variables in the current compile unit. self.expect("target variable", substrs = ['my_global_char', From joelrdillon at gmail.com Wed Feb 1 17:09:23 2012 From: joelrdillon at gmail.com (Joel Dillon) Date: Wed, 1 Feb 2012 18:09:23 -0500 Subject: [Lldb-commits] [PATCH] fix minor compiler errors for Ubuntu 11.04/gcc 4.6.1 Message-ID: Index: source/Plugins/Process/Utility/RegisterContextDarwin_i386.h =================================================================== --- source/Plugins/Process/Utility/RegisterContextDarwin_i386.h (revision 149184) +++ source/Plugins/Process/Utility/RegisterContextDarwin_i386.h (working copy) @@ -11,6 +11,8 @@ #define liblldb_RegisterContextDarwin_i386_h_ // C Includes +#include + // C++ Includes // Other libraries and framework includes // Project includes Index: source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h =================================================================== --- source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h (revision 149184) +++ source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.h (working copy) @@ -11,6 +11,7 @@ #define liblldb_RegisterContextDarwin_x86_64_h_ // C Includes +#include // C++ Includes // Other libraries and framework includes // Project includes Index: source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp =================================================================== --- source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp (revision 149184) +++ source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp (working copy) @@ -11,6 +11,7 @@ // C Includes // C++ Includes // Other libraries and framework includes + #include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/DataExtractor.h" #include "lldb/Core/Log.h" Index: source/Core/Stream.cpp =================================================================== --- source/Core/Stream.cpp (revision 149184) +++ source/Core/Stream.cpp (working copy) @@ -284,7 +284,7 @@ Stream& Stream::operator<< (void *p) { - Printf ("0x%.*tx", (int)sizeof(void*) * 2, (ptrdiff_t)p); + Printf ("0x%.*tx", (int)sizeof(void*) * 2, (std::ptrdiff_t)p); return *this; } From gclayton at apple.com Wed Feb 1 18:12:47 2012 From: gclayton at apple.com (Greg Clayton) Date: Thu, 02 Feb 2012 00:12:47 -0000 Subject: [Lldb-commits] [lldb] r149564 - /lldb/trunk/scripts/Python/python-extensions.swig Message-ID: <20120202001247.95E0B2A6C12C@llvm.org> Author: gclayton Date: Wed Feb 1 18:12:47 2012 New Revision: 149564 URL: http://llvm.org/viewvc/llvm-project?rev=149564&view=rev Log: When outputting hex values use unsigned integer values so we don't get negative hex values. Also added a very rudimentary version of the == and != operators to the lldb.value helper class. Modified: lldb/trunk/scripts/Python/python-extensions.swig Modified: lldb/trunk/scripts/Python/python-extensions.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=149564&r1=149563&r2=149564&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-extensions.swig (original) +++ lldb/trunk/scripts/Python/python-extensions.swig Wed Feb 1 18:12:47 2012 @@ -515,10 +515,15 @@ return float (self.sbvalue.GetValueAsSigned()) def __oct__(self): - return '0%o' % self.sbvalue.GetValueAsSigned() + return '0%o' % self.sbvalue.GetValueAsUnsigned() def __hex__(self): - return '0x%x' % self.sbvalue.GetValueAsSigned() + return '0x%x' % self.sbvalue.GetValueAsUnsigned() + def __eq__(self, other): + return self.sbvalue.GetValueAsUnsigned() == self.sbvalue.GetValueAsUnsigned() + + def __neq__(self, other): + return not self.__eq__(other) %} From gclayton at apple.com Wed Feb 1 18:33:56 2012 From: gclayton at apple.com (Greg Clayton) Date: Thu, 02 Feb 2012 00:33:56 -0000 Subject: [Lldb-commits] [lldb] r149570 - /lldb/tags/lldb-111/ Message-ID: <20120202003356.916E02A6C12C@llvm.org> Author: gclayton Date: Wed Feb 1 18:33:56 2012 New Revision: 149570 URL: http://llvm.org/viewvc/llvm-project?rev=149570&view=rev Log: lldb-111 Added: lldb/tags/lldb-111/ - copied from r149569, lldb/tags/lldb-110/ From gclayton at apple.com Wed Feb 1 19:12:04 2012 From: gclayton at apple.com (Greg Clayton) Date: Thu, 02 Feb 2012 01:12:04 -0000 Subject: [Lldb-commits] [lldb] r149577 - /lldb/tags/lldb-111/tools/driver/Driver.cpp Message-ID: <20120202011204.4C96F2A6C12C@llvm.org> Author: gclayton Date: Wed Feb 1 19:12:04 2012 New Revision: 149577 URL: http://llvm.org/viewvc/llvm-project?rev=149577&view=rev Log: Don't hose bash terminal settings when exiting LLDB. This only happened in bash (csh and tcsh weren't affected). Modified: lldb/tags/lldb-111/tools/driver/Driver.cpp Modified: lldb/tags/lldb-111/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/tags/lldb-111/tools/driver/Driver.cpp?rev=149577&r1=149576&r2=149577&view=diff ============================================================================== --- lldb/tags/lldb-111/tools/driver/Driver.cpp (original) +++ lldb/tags/lldb-111/tools/driver/Driver.cpp Wed Feb 1 19:12:04 2012 @@ -37,6 +37,7 @@ using namespace lldb; static void reset_stdin_termios (); +static bool g_old_stdin_termios_is_valid = false; static struct termios g_old_stdin_termios; static char *g_debugger_name = (char *) ""; @@ -47,7 +48,11 @@ static void reset_stdin_termios () { - ::tcsetattr (STDIN_FILENO, TCSANOW, &g_old_stdin_termios); + if (g_old_stdin_termios_is_valid) + { + g_old_stdin_termios_is_valid = false; + ::tcsetattr (STDIN_FILENO, TCSANOW, &g_old_stdin_termios); + } } typedef struct @@ -1109,7 +1114,10 @@ // struct termios stdin_termios; if (::tcgetattr(STDIN_FILENO, &g_old_stdin_termios) == 0) + { + g_old_stdin_termios_is_valid = true; atexit (reset_stdin_termios); + } ::setbuf (stdin, NULL); ::setbuf (stdout, NULL); @@ -1348,10 +1356,6 @@ { if (event_type & SBCommandInterpreter::eBroadcastBitQuitCommandReceived) { - editline_output_pty.CloseMasterFileDescriptor(); - master_out_comm.Disconnect(); - out_comm_2.Disconnect(); - fclose (stdin); done = true; } else if (event_type & SBCommandInterpreter::eBroadcastBitAsynchronousErrorData) @@ -1369,7 +1373,11 @@ } } - reset_stdin_termios (); + editline_output_pty.CloseMasterFileDescriptor(); + master_out_comm.Disconnect(); + out_comm_2.Disconnect(); + reset_stdin_termios(); + fclose (stdin); CloseIOChannelFile (); From gclayton at apple.com Wed Feb 1 23:48:17 2012 From: gclayton at apple.com (Greg Clayton) Date: Thu, 02 Feb 2012 05:48:17 -0000 Subject: [Lldb-commits] [lldb] r149593 - in /lldb/trunk/source/Plugins/SymbolFile/DWARF: DWARFDebugInfoEntry.cpp DWARFDebugInfoEntry.h SymbolFileDWARF.cpp SymbolFileDWARF.h Message-ID: <20120202054817.58C6B2A6C12C@llvm.org> Author: gclayton Date: Wed Feb 1 23:48:16 2012 New Revision: 149593 URL: http://llvm.org/viewvc/llvm-project?rev=149593&view=rev Log: Fixed an issue where we might accept the wrong type when completing a type when we have a forward declaration. We always have found a type by basename, but now we also compare the decl context of the die we are trying to complete with the matches we find from the accelerator tables to ensure we get the right one. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=149593&r1=149592&r2=149593&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Wed Feb 1 23:48:16 2012 @@ -1726,6 +1726,18 @@ } } +void +DWARFDebugInfoEntry::GetDeclContextDIEs (SymbolFileDWARF* dwarf2Data, + DWARFCompileUnit* cu, + DWARFDIECollection &decl_context_dies) const +{ + const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu); + if (parent_decl_ctx_die && parent_decl_ctx_die != this) + { + decl_context_dies.Append(parent_decl_ctx_die); + parent_decl_ctx_die->GetDeclContextDIEs (dwarf2Data, cu, decl_context_dies); + } +} const DWARFDebugInfoEntry * DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h?rev=149593&r1=149592&r2=149593&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h Wed Feb 1 23:48:16 2012 @@ -355,6 +355,10 @@ const DWARFDebugInfoEntry* GetFirstChild() const { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; } + void GetDeclContextDIEs (SymbolFileDWARF* dwarf2Data, + DWARFCompileUnit* cu, + DWARFDIECollection &decl_context_dies) const; + const DWARFDebugInfoEntry* GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, DWARFCompileUnit* cu) const; const DWARFDebugInfoEntry* GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=149593&r1=149592&r2=149593&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Feb 1 23:48:16 2012 @@ -4045,6 +4045,60 @@ return type_sp; } +bool +SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, + DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) +{ + assert (die1 != die2); + DWARFDIECollection decl_ctx_1; + DWARFDIECollection decl_ctx_2; + die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); + die1->GetDeclContextDIEs (this, cu2, decl_ctx_2); + const size_t count1 = decl_ctx_1.Size(); + const size_t count2 = decl_ctx_2.Size(); + if (count1 != count2) + return false; + const DWARFDebugInfoEntry *decl_ctx_die1; + const DWARFDebugInfoEntry *decl_ctx_die2; + size_t i; + for (i=0; iTag() != decl_ctx_die2->Tag()) + return false; + } + // Make sure the top item in the decl context die array is always a compile unit +#if defined LLDB_CONFIGURATION_DEBUG + assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); +#endif + // Always skip the compile unit when comparing by only iterating up to + // "count1 - 1" + for (i=0; iGetName(this, cu1); + const char *name2 = decl_ctx_die1->GetName(this, cu2); + // If the string was from a DW_FORM_strp, then the pointer will often + // be the same! + if (name1 != name2) + { + if (name1 && name2) + { + // If the strings don't compare, we are done... + if (strcmp(name1, name2) != 0) + return false; + } + else + { + // One name was NULL while the other wasn't + return false; + } + } + } + return true; +} // This function can be used when a DIE is found that is a forward declaration // DIE and we want to try and find a type that has the complete definition. @@ -4136,19 +4190,23 @@ if (try_resolving_type) { - Type *resolved_type = ResolveType (type_cu, type_die, false); - if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) + // Make sure the decl contexts match all the way up + if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) { - DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", - MakeUserID(die->GetOffset()), - MakeUserID(curr_cu->GetOffset()), - m_obj_file->GetFileSpec().GetFilename().AsCString(), - MakeUserID(type_die->GetOffset()), - MakeUserID(type_cu->GetOffset())); - - m_die_to_type[die] = resolved_type; - type_sp = resolved_type->shared_from_this(); - break; + Type *resolved_type = ResolveType (type_cu, type_die, false); + if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) + { + DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n", + MakeUserID(die->GetOffset()), + MakeUserID(curr_cu->GetOffset()), + m_obj_file->GetFileSpec().GetFilename().AsCString(), + MakeUserID(type_die->GetOffset()), + MakeUserID(type_cu->GetOffset())); + + m_die_to_type[die] = resolved_type; + type_sp = resolved_type; + break; + } } } } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=149593&r1=149592&r2=149593&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Wed Feb 1 23:48:16 2012 @@ -503,6 +503,9 @@ int tag_decl_kind, const lldb_private::ClangASTContext::TemplateParameterInfos &template_param_infos); + bool + DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, + DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2); SymbolFileDWARFDebugMap * m_debug_map_symfile; clang::TranslationUnitDecl * m_clang_tu_decl; From granata.enrico at gmail.com Thu Feb 2 11:26:00 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Thu, 02 Feb 2012 17:26:00 -0000 Subject: [Lldb-commits] [lldb] r149606 - /lldb/trunk/scripts/Python/build-swig-Python.sh Message-ID: <20120202172600.701472A6C12C@llvm.org> Author: enrico Date: Thu Feb 2 11:26:00 2012 New Revision: 149606 URL: http://llvm.org/viewvc/llvm-project?rev=149606&view=rev Log: ensure that changes to the typemaps are properly detected and cause SWIG to rebuild LLDBWrapPython.cpp Modified: lldb/trunk/scripts/Python/build-swig-Python.sh Modified: lldb/trunk/scripts/Python/build-swig-Python.sh URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/build-swig-Python.sh?rev=149606&r1=149605&r2=149606&view=diff ============================================================================== --- lldb/trunk/scripts/Python/build-swig-Python.sh (original) +++ lldb/trunk/scripts/Python/build-swig-Python.sh Thu Feb 2 11:26:00 2012 @@ -22,6 +22,7 @@ swig_input_file=${SRC_ROOT}/scripts/lldb.swig swig_python_extensions=${SRC_ROOT}/scripts/Python/python-extensions.swig swig_python_wrapper=${SRC_ROOT}/scripts/Python/python-wrapper.swig +swig_python_typemaps=${SRC_ROOT}/scripts/Python/python-typemaps.swig if [ "x$SDKROOT" = "x" ] ; then @@ -209,6 +210,19 @@ fi fi +if [ $NeedToUpdate == 0 ] +then + if [ ${swig_python_typemaps} -nt ${swig_output_file} ] + then + NeedToUpdate=1 + if [ $Debug == 1 ] + then + echo "${swig_python_typemaps} is newer than ${swig_output_file}" + echo "swig file will need to be re-built." + fi + fi +fi + os_name=`uname -s` python_version=`/usr/bin/python --version 2>&1 | sed -e 's,Python ,,' -e 's,[.][0-9],,2' -e 's,[a-z][a-z][0-9],,'` From gclayton at apple.com Thu Feb 2 12:17:00 2012 From: gclayton at apple.com (Greg Clayton) Date: Thu, 02 Feb 2012 18:17:00 -0000 Subject: [Lldb-commits] [lldb] r149609 - /lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Message-ID: <20120202181700.1AF5D2A6C12C@llvm.org> Author: gclayton Date: Thu Feb 2 12:16:59 2012 New Revision: 149609 URL: http://llvm.org/viewvc/llvm-project?rev=149609&view=rev Log: Fixed a build breakage when trying to assign a shared pointer using a raw pointer. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=149609&r1=149608&r2=149609&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Feb 2 12:16:59 2012 @@ -4204,7 +4204,7 @@ MakeUserID(type_cu->GetOffset())); m_die_to_type[die] = resolved_type; - type_sp = resolved_type; + type_sp = resolved_type->shared_from_this(); break; } } From gclayton at apple.com Thu Feb 2 13:23:23 2012 From: gclayton at apple.com (Greg Clayton) Date: Thu, 02 Feb 2012 19:23:23 -0000 Subject: [Lldb-commits] [lldb] r149622 - /lldb/trunk/tools/debugserver/source/DNB.cpp Message-ID: <20120202192323.14AA92A6C12C@llvm.org> Author: gclayton Date: Thu Feb 2 13:23:22 2012 New Revision: 149622 URL: http://llvm.org/viewvc/llvm-project?rev=149622&view=rev Log: Kill our child process that we launch when we can't get the task_for_pid() otherwise we will have a launched process stopped at the entry point and it will get reparented when debugserver goes away and we won't be able to kill the process later. Modified: lldb/trunk/tools/debugserver/source/DNB.cpp Modified: lldb/trunk/tools/debugserver/source/DNB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=149622&r1=149621&r2=149622&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/DNB.cpp (original) +++ lldb/trunk/tools/debugserver/source/DNB.cpp Thu Feb 2 13:23:22 2012 @@ -250,6 +250,10 @@ if (processSP->Task().TaskPortForProcessID (launch_err) == TASK_NULL) { // We failed to get the task for our process ID which is bad. + // Kill our process otherwise it will be stopped at the entry + // point and get reparented to someone else and never go away. + kill (SIGKILL, pid); + if (err_str && err_len > 0) { if (launch_err.AsString()) From gclayton at apple.com Thu Feb 2 13:28:31 2012 From: gclayton at apple.com (Greg Clayton) Date: Thu, 02 Feb 2012 19:28:31 -0000 Subject: [Lldb-commits] [lldb] r149623 - /lldb/trunk/tools/driver/Driver.cpp Message-ID: <20120202192831.B17B42A6C12C@llvm.org> Author: gclayton Date: Thu Feb 2 13:28:31 2012 New Revision: 149623 URL: http://llvm.org/viewvc/llvm-project?rev=149623&view=rev Log: Fixed terminal settings not being properly restored when "quit" was run. This affected bash users. Modified: lldb/trunk/tools/driver/Driver.cpp Modified: lldb/trunk/tools/driver/Driver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=149623&r1=149622&r2=149623&view=diff ============================================================================== --- lldb/trunk/tools/driver/Driver.cpp (original) +++ lldb/trunk/tools/driver/Driver.cpp Thu Feb 2 13:28:31 2012 @@ -37,6 +37,7 @@ using namespace lldb; static void reset_stdin_termios (); +static bool g_old_stdin_termios_is_valid = false; static struct termios g_old_stdin_termios; static char *g_debugger_name = (char *) ""; @@ -47,7 +48,11 @@ static void reset_stdin_termios () { - ::tcsetattr (STDIN_FILENO, TCSANOW, &g_old_stdin_termios); + if (g_old_stdin_termios_is_valid) + { + g_old_stdin_termios_is_valid = false; + ::tcsetattr (STDIN_FILENO, TCSANOW, &g_old_stdin_termios); + } } typedef struct @@ -1109,7 +1114,10 @@ // struct termios stdin_termios; if (::tcgetattr(STDIN_FILENO, &g_old_stdin_termios) == 0) + { + g_old_stdin_termios_is_valid = true; atexit (reset_stdin_termios); + } ::setbuf (stdin, NULL); ::setbuf (stdout, NULL); @@ -1348,10 +1356,6 @@ { if (event_type & SBCommandInterpreter::eBroadcastBitQuitCommandReceived) { - editline_output_pty.CloseMasterFileDescriptor(); - master_out_comm.Disconnect(); - out_comm_2.Disconnect(); - fclose (stdin); done = true; } else if (event_type & SBCommandInterpreter::eBroadcastBitAsynchronousErrorData) @@ -1369,7 +1373,11 @@ } } - reset_stdin_termios (); + editline_output_pty.CloseMasterFileDescriptor(); + master_out_comm.Disconnect(); + out_comm_2.Disconnect(); + reset_stdin_termios(); + fclose (stdin); CloseIOChannelFile (); From johnny.chen at apple.com Thu Feb 2 13:55:18 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 02 Feb 2012 19:55:18 -0000 Subject: [Lldb-commits] [lldb] r149629 - in /lldb/trunk: source/Core/Value.cpp test/functionalities/target_command/TestTargetCommand.py Message-ID: <20120202195518.B00A62A6C12C@llvm.org> Author: johnny Date: Thu Feb 2 13:55:18 2012 New Revision: 149629 URL: http://llvm.org/viewvc/llvm-project?rev=149629&view=rev Log: For processes which are not in one of the "launched and stopped" state, 'target variable' command should use Target::ReadMemory() call to read from the file section offset address. Also remove the @expectedFailure decorator.. 'target variable' command fails if the target program has been run rdar://problem/9763907 Modified: lldb/trunk/source/Core/Value.cpp lldb/trunk/test/functionalities/target_command/TestTargetCommand.py Modified: lldb/trunk/source/Core/Value.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Value.cpp?rev=149629&r1=149628&r2=149629&view=diff ============================================================================== --- lldb/trunk/source/Core/Value.cpp (original) +++ lldb/trunk/source/Core/Value.cpp Thu Feb 2 13:55:18 2012 @@ -425,7 +425,20 @@ { Address so_addr(address, objfile->GetSectionList()); addr_t load_address = so_addr.GetLoadAddress (exe_ctx->GetTargetPtr()); - if (load_address != LLDB_INVALID_ADDRESS) + bool process_launched_and_stopped = false; + if (exe_ctx->GetProcessPtr()) + switch (exe_ctx->GetProcessPtr()->GetState()) + { + default: + break; + case eStateInvalid: + case eStateSuspended: + case eStateCrashed: + case eStateStopped: + process_launched_and_stopped = true; + } + // Don't use the load address if the process has exited. + if (load_address != LLDB_INVALID_ADDRESS && process_launched_and_stopped) { resolved = true; address = load_address; Modified: lldb/trunk/test/functionalities/target_command/TestTargetCommand.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/target_command/TestTargetCommand.py?rev=149629&r1=149628&r2=149629&view=diff ============================================================================== --- lldb/trunk/test/functionalities/target_command/TestTargetCommand.py (original) +++ lldb/trunk/test/functionalities/target_command/TestTargetCommand.py Thu Feb 2 13:55:18 2012 @@ -36,7 +36,6 @@ # rdar://problem/9763907 # 'target variable' command fails if the target program has been run - @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_target_variable_command_with_dsym(self): """Test 'target variable' command before and after starting the inferior.""" From johnny.chen at apple.com Thu Feb 2 16:11:14 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 02 Feb 2012 22:11:14 -0000 Subject: [Lldb-commits] [lldb] r149637 - /lldb/trunk/source/Core/Value.cpp Message-ID: <20120202221114.291542A6C12C@llvm.org> Author: johnny Date: Thu Feb 2 16:11:13 2012 New Revision: 149637 URL: http://llvm.org/viewvc/llvm-project?rev=149637&view=rev Log: Should have used the convenience function: bool lldb_private::StateIsStoppedState (StateType state, bool must_exist) instead. Modified: lldb/trunk/source/Core/Value.cpp Modified: lldb/trunk/source/Core/Value.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Value.cpp?rev=149637&r1=149636&r2=149637&view=diff ============================================================================== --- lldb/trunk/source/Core/Value.cpp (original) +++ lldb/trunk/source/Core/Value.cpp Thu Feb 2 16:11:13 2012 @@ -16,6 +16,7 @@ #include "lldb/Core/DataExtractor.h" #include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Module.h" +#include "lldb/Core/State.h" #include "lldb/Core/Stream.h" #include "lldb/Symbol/ClangASTType.h" #include "lldb/Symbol/ClangASTContext.h" @@ -425,18 +426,9 @@ { Address so_addr(address, objfile->GetSectionList()); addr_t load_address = so_addr.GetLoadAddress (exe_ctx->GetTargetPtr()); - bool process_launched_and_stopped = false; - if (exe_ctx->GetProcessPtr()) - switch (exe_ctx->GetProcessPtr()->GetState()) - { - default: - break; - case eStateInvalid: - case eStateSuspended: - case eStateCrashed: - case eStateStopped: - process_launched_and_stopped = true; - } + bool process_launched_and_stopped = exe_ctx->GetProcessPtr() + ? StateIsStoppedState(exe_ctx->GetProcessPtr()->GetState(), true /* must_exist */) + : false; // Don't use the load address if the process has exited. if (load_address != LLDB_INVALID_ADDRESS && process_launched_and_stopped) { From granata.enrico at gmail.com Thu Feb 2 17:34:52 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Thu, 02 Feb 2012 23:34:52 -0000 Subject: [Lldb-commits] [lldb] r149644 - in /lldb/trunk: include/lldb/Core/FormatClasses.h include/lldb/Core/FormatNavigator.h source/Commands/CommandObjectType.cpp source/Core/FormatClasses.cpp source/Core/FormatManager.cpp test/functionalities/data-formatter/rdar-10642615/ test/functionalities/data-formatter/rdar-10642615/Makefile test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py test/functionalities/data-formatter/rdar-10642615/main.cpp Message-ID: <20120202233452.9BF6E2A6C12C@llvm.org> Author: enrico Date: Thu Feb 2 17:34:52 2012 New Revision: 149644 URL: http://llvm.org/viewvc/llvm-project?rev=149644&view=rev Log: Added a new --omit-names (-O, uppercase letter o) option to "type summary add". When used in conjunction with --inline-children, this option will cause the names of the values to be omitted from the output. This can be beneficial in cases such as vFloat, where it will compact the representation from ([0]=1,[1]=2,[2]=3,[3]=4) to (1, 2, 3, 4). Added a test case to check that the new option works correctly. Also took some time to revisit SummaryFormat and related classes and tweak them for added readability and maintainability. Finally, added a new class name to which the std::string summary should be applied. Added: lldb/trunk/test/functionalities/data-formatter/rdar-10642615/ lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Makefile lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp Modified: lldb/trunk/include/lldb/Core/FormatClasses.h lldb/trunk/include/lldb/Core/FormatNavigator.h lldb/trunk/source/Commands/CommandObjectType.cpp lldb/trunk/source/Core/FormatClasses.cpp lldb/trunk/source/Core/FormatManager.cpp Modified: lldb/trunk/include/lldb/Core/FormatClasses.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatClasses.h?rev=149644&r1=149643&r2=149644&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FormatClasses.h (original) +++ lldb/trunk/include/lldb/Core/FormatClasses.h Thu Feb 2 17:34:52 2012 @@ -566,55 +566,206 @@ }; -struct SummaryFormat +class SummaryFormat { +public: + class Flags + { + public: + + Flags () : + m_flags (FVCascades) + {} + + Flags (const Flags& other) : + m_flags (other.m_flags) + {} + + Flags& + operator = (const Flags& rhs) + { + if (&rhs != this) + m_flags = rhs.m_flags; + + return *this; + } + + Flags& + Clear() + { + m_flags = 0; + return *this; + } + + bool + GetCascades () const + { + return (m_flags & FVCascades) == FVCascades; + } + + Flags& + SetCascades (bool value = true) + { + if (value) + m_flags |= FVCascades; + else + m_flags &= ~FVCascades; + return *this; + } + + bool + GetSkipPointers () const + { + return (m_flags & FVSkipPointers) == FVSkipPointers; + } + + Flags& + SetSkipPointers (bool value = true) + { + if (value) + m_flags |= FVSkipPointers; + else + m_flags &= ~FVSkipPointers; + return *this; + } + + bool + GetSkipReferences () const + { + return (m_flags & FVSkipReferences) == FVSkipReferences; + } + + Flags& + SetSkipReferences (bool value = true) + { + if (value) + m_flags |= FVSkipReferences; + else + m_flags &= ~FVSkipReferences; + return *this; + } + + bool + GetDontShowChildren () const + { + return (m_flags & FVDontShowChildren) == FVDontShowChildren; + } + + Flags& + SetDontShowChildren (bool value = true) + { + if (value) + m_flags |= FVDontShowChildren; + else + m_flags &= ~FVDontShowChildren; + return *this; + } + + bool + GetDontShowValue () const + { + return (m_flags & FVDontShowValue) == FVDontShowValue; + } + + Flags& + SetDontShowValue (bool value = true) + { + if (value) + m_flags |= FVDontShowValue; + else + m_flags &= ~FVDontShowValue; + return *this; + } + + bool + GetShowMembersOneLiner () const + { + return (m_flags & FVShowMembersOneLiner) == FVShowMembersOneLiner; + } + + Flags& + SetShowMembersOneLiner (bool value = true) + { + if (value) + m_flags |= FVShowMembersOneLiner; + else + m_flags &= ~FVShowMembersOneLiner; + return *this; + } + + bool + GetHideItemNames () const + { + return (m_flags & FVHideItemNames) == FVHideItemNames; + } + + Flags& + SetHideItemNames (bool value = true) + { + if (value) + m_flags |= FVHideItemNames; + else + m_flags &= ~FVHideItemNames; + return *this; + } + + private: + uint32_t m_flags; + enum FlagValues + { + FVCascades = 0x0001u, + FVSkipPointers = 0x0002u, + FVSkipReferences = 0x0004u, + FVDontShowChildren = 0x0008u, + FVDontShowValue = 0x0010u, + FVShowMembersOneLiner = 0x0020u, + FVHideItemNames = 0x0040u + }; + }; + uint32_t m_my_revision; - bool m_cascades; - bool m_skip_pointers; - bool m_skip_references; - bool m_dont_show_children; - bool m_dont_show_value; - bool m_show_members_oneliner; - - SummaryFormat(bool casc = false, - bool skipptr = false, - bool skipref = false, - bool nochildren = true, - bool novalue = true, - bool oneliner = false); + Flags m_flags; + + SummaryFormat(const SummaryFormat::Flags& flags); bool Cascades() const { - return m_cascades; + return m_flags.GetCascades(); } bool SkipsPointers() const { - return m_skip_pointers; + return m_flags.GetSkipPointers(); } bool SkipsReferences() const { - return m_skip_references; + return m_flags.GetSkipReferences(); } bool DoesPrintChildren() const { - return !m_dont_show_children; + return !m_flags.GetDontShowChildren(); } bool DoesPrintValue() const { - return !m_dont_show_value; + return !m_flags.GetDontShowValue(); } bool IsOneliner() const { - return m_show_members_oneliner; + return m_flags.GetShowMembersOneLiner(); + } + + bool + HideNames() const + { + return m_flags.GetHideItemNames(); } virtual @@ -639,13 +790,8 @@ { std::string m_format; - StringSummaryFormat(bool casc = false, - bool skipptr = false, - bool skipref = false, - bool nochildren = true, - bool novalue = true, - bool oneliner = false, - std::string f = ""); + StringSummaryFormat(const SummaryFormat::Flags& flags, + std::string f); std::string GetFormat() const @@ -674,14 +820,9 @@ std::string m_function_name; std::string m_python_script; - ScriptSummaryFormat(bool casc = false, - bool skipptr = false, - bool skipref = false, - bool nochildren = true, - bool novalue = true, - bool oneliner = false, - std::string fname = "", - std::string pscri = ""); + ScriptSummaryFormat(const SummaryFormat::Flags& flags, + std::string fname, + std::string pscri); std::string GetFunctionName() const Modified: lldb/trunk/include/lldb/Core/FormatNavigator.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatNavigator.h?rev=149644&r1=149643&r2=149644&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/FormatNavigator.h (original) +++ lldb/trunk/include/lldb/Core/FormatNavigator.h Thu Feb 2 17:34:52 2012 @@ -511,7 +511,7 @@ { if (log) log->Printf("stripping reference"); - if (Get(valobj,type.getNonReferenceType(),entry, use_dynamic, reason) && !entry->m_skip_references) + if (Get(valobj,type.getNonReferenceType(),entry, use_dynamic, reason) && !entry->SkipsReferences()) { reason |= lldb_private::eFormatterChoiceCriterionStrippedPointerReference; return true; @@ -554,7 +554,7 @@ if (log) log->Printf("stripping pointer"); clang::QualType pointee = typePtr->getPointeeType(); - if (Get(valobj, pointee, entry, use_dynamic, reason) && !entry->m_skip_pointers) + if (Get(valobj, pointee, entry, use_dynamic, reason) && !entry->SkipsPointers()) { reason |= lldb_private::eFormatterChoiceCriterionStrippedPointerReference; return true; @@ -596,7 +596,7 @@ ValueObject* target = valobj.Dereference(error).get(); if (error.Fail() || !target) return false; - if (Get(*target, typePtr->getPointeeType(), entry, use_dynamic, reason) && !entry->m_skip_pointers) + if (Get(*target, typePtr->getPointeeType(), entry, use_dynamic, reason) && !entry->SkipsPointers()) { reason |= lldb_private::eFormatterChoiceCriterionStrippedPointerReference; return true; @@ -621,7 +621,7 @@ if (log) log->Printf("got a parent class for this ObjC class"); clang::QualType ivar_qual_type(ast->getObjCInterfaceType(superclass_interface_decl)); - if (Get(valobj, ivar_qual_type, entry, use_dynamic, reason) && entry->m_cascades) + if (Get(valobj, ivar_qual_type, entry, use_dynamic, reason) && entry->Cascades()) { reason |= lldb_private::eFormatterChoiceCriterionNavigatedBaseClasses; return true; @@ -650,7 +650,7 @@ end = record->bases_end(); for (pos = record->bases_begin(); pos != end; pos++) { - if ((Get(valobj, pos->getType(), entry, use_dynamic, reason)) && entry->m_cascades) + if ((Get(valobj, pos->getType(), entry, use_dynamic, reason)) && entry->Cascades()) { reason |= lldb_private::eFormatterChoiceCriterionNavigatedBaseClasses; return true; @@ -664,7 +664,7 @@ end = record->vbases_end(); for (pos = record->vbases_begin(); pos != end; pos++) { - if ((Get(valobj, pos->getType(), entry, use_dynamic, reason)) && entry->m_cascades) + if ((Get(valobj, pos->getType(), entry, use_dynamic, reason)) && entry->Cascades()) { reason |= lldb_private::eFormatterChoiceCriterionNavigatedBaseClasses; return true; @@ -680,7 +680,7 @@ { if (log) log->Printf("stripping typedef"); - if ((Get(valobj, type_tdef->getDecl()->getUnderlyingType(), entry, use_dynamic, reason)) && entry->m_cascades) + if ((Get(valobj, type_tdef->getDecl()->getUnderlyingType(), entry, use_dynamic, reason)) && entry->Cascades()) { reason |= lldb_private::eFormatterChoiceCriterionNavigatedTypedefs; return true; Modified: lldb/trunk/source/Commands/CommandObjectType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=149644&r1=149643&r2=149644&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectType.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectType.cpp Thu Feb 2 17:34:52 2012 @@ -37,38 +37,22 @@ public: - bool m_skip_pointers; - bool m_skip_references; - bool m_cascade; + SummaryFormat::Flags m_flags; + StringList m_target_types; StringList m_user_source; - bool m_no_children; - bool m_no_value; - bool m_one_liner; bool m_regex; - + ConstString m_name; std::string m_category; - ScriptAddOptions(bool sptr, - bool sref, - bool casc, - bool noch, - bool novl, - bool onel, + ScriptAddOptions(const SummaryFormat::Flags& flags, bool regx, const ConstString& name, std::string catg) : - m_skip_pointers(sptr), - m_skip_references(sref), - m_cascade(casc), - m_target_types(), - m_user_source(), - m_no_children(noch), - m_no_value(novl), - m_one_liner(onel), + m_flags(flags), m_regex(regx), m_name(name), m_category(catg) @@ -149,12 +133,7 @@ // Instance variables to hold the values for command options. - bool m_cascade; - bool m_no_children; - bool m_no_value; - bool m_one_liner; - bool m_skip_references; - bool m_skip_pointers; + SummaryFormat::Flags m_flags; bool m_regex; std::string m_format_string; ConstString m_name; @@ -872,12 +851,7 @@ // now I have a valid function name, let's add this as script for every type in the list SummaryFormatSP script_format; - script_format.reset(new ScriptSummaryFormat(options->m_cascade, - options->m_skip_pointers, - options->m_skip_references, - options->m_no_children, - options->m_no_value, - options->m_one_liner, + script_format.reset(new ScriptSummaryFormat(options->m_flags, std::string(funct_name), options->m_user_source.CopyList(" "))); @@ -951,27 +925,27 @@ switch (short_option) { case 'C': - m_cascade = Args::StringToBoolean(option_arg, true, &success); + m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success)); if (!success) error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg); break; case 'e': - m_no_children = false; + m_flags.SetDontShowChildren(false); break; case 'v': - m_no_value = true; + m_flags.SetDontShowValue(true); break; case 'c': - m_one_liner = true; + m_flags.SetShowMembersOneLiner(true); break; case 's': m_format_string = std::string(option_arg); break; case 'p': - m_skip_pointers = true; + m_flags.SetSkipPointers(true); break; case 'r': - m_skip_references = true; + m_flags.SetSkipReferences(true); break; case 'x': m_regex = true; @@ -993,6 +967,9 @@ case 'w': m_category = std::string(option_arg); break; + case 'O': + m_flags.SetHideItemNames(true); + break; default: error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); break; @@ -1004,12 +981,9 @@ void CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting () { - m_cascade = true; - m_no_children = true; - m_no_value = false; - m_one_liner = false; - m_skip_references = false; - m_skip_pointers = false; + m_flags.Clear().SetCascades().SetDontShowChildren().SetDontShowValue(false); + m_flags.SetShowMembersOneLiner(false).SetSkipPointers(false).SetSkipReferences(false).SetHideItemNames(false); + m_regex = false; m_name.Clear(); m_python_script = ""; @@ -1080,12 +1054,7 @@ return false; } - script_format.reset(new ScriptSummaryFormat(m_options.m_cascade, - m_options.m_skip_pointers, - m_options.m_skip_references, - m_options.m_no_children, - m_options.m_no_value, - m_options.m_one_liner, + script_format.reset(new ScriptSummaryFormat(m_options.m_flags, std::string(funct_name), " " + m_options.m_python_function + "(valobj,dict)")); } @@ -1122,23 +1091,13 @@ return false; } - script_format.reset(new ScriptSummaryFormat(m_options.m_cascade, - m_options.m_skip_pointers, - m_options.m_skip_references, - m_options.m_no_children, - m_options.m_no_value, - m_options.m_one_liner, + script_format.reset(new ScriptSummaryFormat(m_options.m_flags, std::string(funct_name), " " + m_options.m_python_script)); } else // use an InputReader to grab Python code from the user { - ScriptAddOptions *options = new ScriptAddOptions(m_options.m_skip_pointers, - m_options.m_skip_references, - m_options.m_cascade, - m_options.m_no_children, - m_options.m_no_value, - m_options.m_one_liner, + ScriptAddOptions *options = new ScriptAddOptions(m_options.m_flags, m_options.m_regex, m_options.m_name, m_options.m_category); @@ -1211,14 +1170,14 @@ return false; } - if (!m_options.m_one_liner && m_options.m_format_string.empty()) + if (!m_options.m_flags.GetShowMembersOneLiner() && m_options.m_format_string.empty()) { result.AppendError("empty summary strings not allowed"); result.SetStatus(eReturnStatusFailed); return false; } - const char* format_cstr = (m_options.m_one_liner ? "" : m_options.m_format_string.c_str()); + const char* format_cstr = (m_options.m_flags.GetShowMembersOneLiner() ? "" : m_options.m_format_string.c_str()); // ${var%S} is an endless recursion, prevent it if (strcmp(format_cstr, "${var%S}") == 0) @@ -1230,15 +1189,10 @@ Error error; - lldb::SummaryFormatSP entry(new StringSummaryFormat(m_options.m_cascade, - m_options.m_skip_pointers, - m_options.m_skip_references, - m_options.m_no_children, - m_options.m_no_value, - m_options.m_one_liner, - format_cstr)); + lldb::SummaryFormatSP entry(new StringSummaryFormat(m_options.m_flags, + format_cstr)); - if (error.Fail()) + if (error.Fail()) { result.AppendError(error.AsCString()); result.SetStatus(eReturnStatusFailed); @@ -1435,6 +1389,7 @@ { LLDB_OPT_SET_ALL, false, "skip-references", 'r', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."}, { LLDB_OPT_SET_ALL, false, "regex", 'x', no_argument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."}, { LLDB_OPT_SET_1 , true, "inline-children", 'c', no_argument, NULL, 0, eArgTypeNone, "If true, inline all child values into summary string."}, + { LLDB_OPT_SET_1 , false, "omit-names", 'O', no_argument, NULL, 0, eArgTypeNone, "If true, omit value names in the summary display."}, { LLDB_OPT_SET_2 , true, "summary-string", 's', required_argument, NULL, 0, eArgTypeSummaryString, "Summary string used to display text and object contents."}, { LLDB_OPT_SET_3, false, "python-script", 'o', required_argument, NULL, 0, eArgTypePythonScript, "Give a one-liner Python script as part of the command."}, { LLDB_OPT_SET_3, false, "python-function", 'F', required_argument, NULL, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type."}, Modified: lldb/trunk/source/Core/FormatClasses.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatClasses.cpp?rev=149644&r1=149643&r2=149644&view=diff ============================================================================== --- lldb/trunk/source/Core/FormatClasses.cpp (original) +++ lldb/trunk/source/Core/FormatClasses.cpp Thu Feb 2 17:34:52 2012 @@ -55,34 +55,14 @@ { } -SummaryFormat::SummaryFormat(bool casc, - bool skipptr, - bool skipref, - bool nochildren, - bool novalue, - bool oneliner) : - m_cascades(casc), - m_skip_pointers(skipptr), - m_skip_references(skipref), - m_dont_show_children(nochildren), - m_dont_show_value(novalue), - m_show_members_oneliner(oneliner) +SummaryFormat::SummaryFormat(const SummaryFormat::Flags& flags) : + m_flags(flags) { } -StringSummaryFormat::StringSummaryFormat(bool casc, - bool skipptr, - bool skipref, - bool nochildren, - bool novalue, - bool oneliner, +StringSummaryFormat::StringSummaryFormat(const SummaryFormat::Flags& flags, std::string f) : - SummaryFormat(casc, - skipptr, - skipref, - nochildren, - novalue, - oneliner), + SummaryFormat(flags), m_format(f) { } @@ -102,7 +82,7 @@ if (frame) sc = frame->GetSymbolContext(lldb::eSymbolContextEverything); - if (m_show_members_oneliner) + if (IsOneliner()) { ValueObjectSP synth_valobj = object->GetSyntheticValue(lldb::eUseSyntheticFilter); const uint32_t num_children = synth_valobj->GetNumChildren(); @@ -117,8 +97,11 @@ { if (idx) s.PutCString(", "); - s.PutCString(child_sp.get()->GetName().AsCString()); - s.PutChar('='); + if (!HideNames()) + { + s.PutCString(child_sp.get()->GetName().AsCString()); + s.PutChar('='); + } child_sp.get()->GetPrintableRepresentation(s); } } @@ -144,32 +127,24 @@ StringSummaryFormat::GetDescription() { StreamString sstr; - sstr.Printf ("`%s`%s%s%s%s%s%s", m_format.c_str(), - m_cascades ? "" : " (not cascading)", - m_dont_show_children ? "" : " (show children)", - m_dont_show_value ? " (hide value)" : "", - m_show_members_oneliner ? " (one-line printout)" : "", - m_skip_pointers ? " (skip pointers)" : "", - m_skip_references ? " (skip references)" : ""); + + sstr.Printf ("`%s`%s%s%s%s%s%s%s", m_format.c_str(), + Cascades() ? "" : " (not cascading)", + !DoesPrintChildren() ? "" : " (show children)", + !DoesPrintValue() ? " (hide value)" : "", + IsOneliner() ? " (one-line printout)" : "", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : "", + HideNames() ? " (hide member names)" : ""); return sstr.GetString(); } #ifndef LLDB_DISABLE_PYTHON -ScriptSummaryFormat::ScriptSummaryFormat(bool casc, - bool skipptr, - bool skipref, - bool nochildren, - bool novalue, - bool oneliner, +ScriptSummaryFormat::ScriptSummaryFormat(const SummaryFormat::Flags& flags, std::string fname, std::string pscri) : - SummaryFormat(casc, - skipptr, - skipref, - nochildren, - novalue, - oneliner), + SummaryFormat(flags), m_function_name(fname), m_python_script(pscri) { @@ -187,12 +162,13 @@ ScriptSummaryFormat::GetDescription() { StreamString sstr; - sstr.Printf ("%s%s%s%s%s%s\n%s", m_cascades ? "" : " (not cascading)", - m_dont_show_children ? "" : " (show children)", - m_dont_show_value ? " (hide value)" : "", - m_show_members_oneliner ? " (one-line printout)" : "", - m_skip_pointers ? " (skip pointers)" : "", - m_skip_references ? " (skip references)" : "", + sstr.Printf ("%s%s%s%s%s%s%s\n%s", Cascades() ? "" : " (not cascading)", + !DoesPrintChildren() ? "" : " (show children)", + !DoesPrintValue() ? " (hide value)" : "", + IsOneliner() ? " (one-line printout)" : "", + SkipsPointers() ? " (skip pointers)" : "", + SkipsReferences() ? " (skip references)" : "", + HideNames() ? " (hide member names)" : "", m_python_script.c_str()); return sstr.GetString(); Modified: lldb/trunk/source/Core/FormatManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=149644&r1=149643&r2=149644&view=diff ============================================================================== --- lldb/trunk/source/Core/FormatManager.cpp (original) +++ lldb/trunk/source/Core/FormatManager.cpp Thu Feb 2 17:34:52 2012 @@ -566,22 +566,24 @@ // add some default stuff // most formats, summaries, ... actually belong to the users' lldbinit file rather than here - lldb::SummaryFormatSP string_format(new StringSummaryFormat(false, - true, - false, - true, - false, - false, - "${var%s}")); - - - lldb::SummaryFormatSP string_array_format(new StringSummaryFormat(false, - true, - false, - false, - false, - false, - "${var%s}")); + lldb::SummaryFormatSP string_format(new StringSummaryFormat(SummaryFormat::Flags().SetCascades(false) + .SetSkipPointers(true) + .SetSkipReferences(false) + .SetDontShowChildren(true) + .SetDontShowValue(false) + .SetShowMembersOneLiner(false) + .SetHideItemNames(false), + "${var%s}")); + + + lldb::SummaryFormatSP string_array_format(new StringSummaryFormat(SummaryFormat::Flags().SetCascades(false) + .SetSkipPointers(true) + .SetSkipReferences(false) + .SetDontShowChildren(false) + .SetDontShowValue(true) + .SetShowMembersOneLiner(false) + .SetHideItemNames(false), + "${var%s}")); lldb::RegularExpressionSP any_size_char_arr(new RegularExpression("char \\[[0-9]+\\]")); @@ -600,12 +602,13 @@ // the GNU libstdc++ are defined regardless, and enabled by default // This is going to be moved to some platform-dependent location // (in the meanwhile, these formatters should work for Mac OS X & Linux) - lldb::SummaryFormatSP std_string_summary_sp(new StringSummaryFormat(true, - false, - false, - true, - true, - false, + lldb::SummaryFormatSP std_string_summary_sp(new StringSummaryFormat(SummaryFormat::Flags().SetCascades(true) + .SetSkipPointers(false) + .SetSkipReferences(false) + .SetDontShowChildren(true) + .SetDontShowValue(true) + .SetShowMembersOneLiner(false) + .SetHideItemNames(false), "${var._M_dataplus._M_p}")); FormatCategory::SharedPointer gnu_category_sp = GetCategory(m_gnu_cpp_category_name); @@ -616,6 +619,9 @@ std_string_summary_sp); gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string,std::allocator >"), std_string_summary_sp); + gnu_category_sp->GetSummaryNavigator()->Add(ConstString("std::basic_string, class std::allocator >"), + std_string_summary_sp); + #ifndef LLDB_DISABLE_PYTHON gnu_category_sp->GetRegexSyntheticNavigator()->Add(RegularExpressionSP(new RegularExpression("^(std::)?vector<.+>$")), @@ -634,12 +640,13 @@ false, "gnu_libstdcpp.StdListSynthProvider"))); - lldb::SummaryFormatSP ObjC_BOOL_summary(new ScriptSummaryFormat(false, - false, - false, - true, - true, - false, + lldb::SummaryFormatSP ObjC_BOOL_summary(new ScriptSummaryFormat(SummaryFormat::Flags().SetCascades(false) + .SetSkipPointers(false) + .SetSkipReferences(false) + .SetDontShowChildren(true) + .SetDontShowValue(true) + .SetShowMembersOneLiner(false) + .SetHideItemNames(false), "objc.BOOL_SummaryProvider", "")); FormatCategory::SharedPointer objc_category_sp = GetCategory(m_objc_category_name); Added: lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Makefile?rev=149644&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Makefile (added) +++ lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Makefile Thu Feb 2 17:34:52 2012 @@ -0,0 +1,7 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + +LDFLAGS += -framework Accelerate \ No newline at end of file Added: lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py?rev=149644&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py (added) +++ lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py Thu Feb 2 17:34:52 2012 @@ -0,0 +1,93 @@ +""" +Test lldb data formatter subsystem. +""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class Radar10642615DataFormatterTestCase(TestBase): + + # test for rdar://problem/10642615 () + mydir = os.path.join("functionalities", "data-formatter", "rdar-10642615") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_with_dsym_and_run_command(self): + """Test data formatter commands.""" + self.buildDsym() + self.data_formatter_commands() + + def test_with_dwarf_and_run_command(self): + """Test data formatter commands.""" + self.buildDwarf() + self.data_formatter_commands() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break at. + self.line = line_number('main.cpp', '// Set break point at this line.') + + def data_formatter_commands(self): + """Test that that file and class static variables display correctly.""" + self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) + + self.expect("breakpoint set -f main.cpp -l %d" % self.line, + BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % + self.line) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # This is the function to remove the custom formats in order to have a + # clean slate for the next test case. + def cleanup(): + self.runCmd('type summary clear', check=False) + + # Execute the cleanup function during test case tear down. + self.addTearDownHook(cleanup) + + self.expect('frame variable value', + substrs = ['[0] = 1', '[2] = 4']) + + self.runCmd("type summary add vFloat --inline-children") + + self.expect('frame variable value', + substrs = ['[0]=1, [1]', ', [2]=4']) + + self.runCmd("type summary add vFloat --inline-children --omit-names") + + self.expect('frame variable value', + substrs = ['1, 0, 4, 0']) + + self.runCmd("type summary add vFloat --inline-children") + + self.expect('frame variable value', + substrs = ['[0]=1, [1]', ', [2]=4']) + + self.runCmd("type summary delete vFloat") + + self.expect('frame variable value', + substrs = ['[0] = 1', '[2] = 4']) + + self.runCmd("type summary add vFloat --omit-names", check=False) # should not work since we're not inlining children + + self.expect('frame variable value', + substrs = ['[0] = 1', '[2] = 4']) + + self.runCmd("type summary add vFloat --inline-children --omit-names") + + self.expect('frame variable value', + substrs = ['1, 0, 4, 0']) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp?rev=149644&view=auto ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp (added) +++ lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp Thu Feb 2 17:34:52 2012 @@ -0,0 +1,20 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include + +int main() +{ + float f[4] __attribute__((__aligned__(16))); + f[0] = 1; + f[2] = 4; + vFloat *vPointer = (vFloat *) f; + vFloat value = *vPointer; + return 0; // Set break point at this line. +} From johnny.chen at apple.com Thu Feb 2 19:14:42 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 03 Feb 2012 01:14:42 -0000 Subject: [Lldb-commits] [lldb] r149656 - /lldb/trunk/test/functionalities/completion/TestCompletion.py Message-ID: <20120203011442.F2CE22A6C12C@llvm.org> Author: johnny Date: Thu Feb 2 19:14:42 2012 New Revision: 149656 URL: http://llvm.org/viewvc/llvm-project?rev=149656&view=rev Log: Add a couple of simple completion test cases for 'target ' and 'target va'. Modified: lldb/trunk/test/functionalities/completion/TestCompletion.py Modified: lldb/trunk/test/functionalities/completion/TestCompletion.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/completion/TestCompletion.py?rev=149656&r1=149655&r2=149656&view=diff ============================================================================== --- lldb/trunk/test/functionalities/completion/TestCompletion.py (original) +++ lldb/trunk/test/functionalities/completion/TestCompletion.py Thu Feb 2 19:14:42 2012 @@ -102,6 +102,17 @@ 'target.process.thread.step-avoid-regexp', 'target.process.thread.trace-thread']) + def test_target_space(self): + """Test that 'target ' completes to ['Available completions:', 'create', 'delete', 'list', + 'modules', 'select', 'stop-hook', 'variable'].""" + self.complete_from_to('target ', + ['Available completions:', 'create', 'delete', 'list', + 'modules', 'select', 'stop-hook', 'variable']) + + def test_target_va(self): + """Test that 'target va' completes to 'target variable '.""" + self.complete_from_to('target va', 'target variable ') + def complete_from_to(self, str_input, patterns): """Test that the completion mechanism completes str_input to patterns, where patterns could be a pattern-string or a list of pattern-strings""" From gclayton at apple.com Thu Feb 2 19:30:31 2012 From: gclayton at apple.com (Greg Clayton) Date: Fri, 03 Feb 2012 01:30:31 -0000 Subject: [Lldb-commits] [lldb] r149658 - in /lldb/trunk: include/lldb/API/SBType.h include/lldb/Symbol/ClangASTContext.h include/lldb/lldb-enumerations.h scripts/Python/interface/SBType.i source/API/SBType.cpp source/Interpreter/ScriptInterpreterPython.cpp source/Symbol/ClangASTContext.cpp Message-ID: <20120203013031.6E63A2A6C12C@llvm.org> Author: gclayton Date: Thu Feb 2 19:30:30 2012 New Revision: 149658 URL: http://llvm.org/viewvc/llvm-project?rev=149658&view=rev Log: Added support to SBType for getting template arguments from a SBType: uint32_t SBType::GetNumberOfTemplateArguments (); lldb::SBType SBType::GetTemplateArgumentType (uint32_t idx); lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind (uint32_t idx); Some lldb::TemplateArgumentKind values don't have a corresponding SBType that will be returned from SBType::GetTemplateArgumentType(). This will help our data formatters do their job by being able to find out the type of template params and do smart things with those. Modified: lldb/trunk/include/lldb/API/SBType.h lldb/trunk/include/lldb/Symbol/ClangASTContext.h lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/scripts/Python/interface/SBType.i lldb/trunk/source/API/SBType.cpp lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/include/lldb/API/SBType.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=149658&r1=149657&r2=149658&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBType.h (original) +++ lldb/trunk/include/lldb/API/SBType.h Thu Feb 2 19:30:30 2012 @@ -124,6 +124,15 @@ lldb::SBTypeMember GetVirtualBaseClassAtIndex (uint32_t idx); + uint32_t + GetNumberOfTemplateArguments (); + + lldb::SBType + GetTemplateArgumentType (uint32_t idx); + + lldb::TemplateArgumentKind + GetTemplateArgumentKind (uint32_t idx); + const char* GetName(); Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=149658&r1=149657&r2=149658&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Feb 2 19:30:30 2012 @@ -593,6 +593,30 @@ bool omit_empty_base_classes, std::vector& child_indexes); + size_t + GetNumTemplateArguments (lldb::clang_type_t clang_type) + { + return GetNumTemplateArguments(getASTContext(), clang_type); + } + + lldb::clang_type_t + GetTemplateArgument (lldb::clang_type_t clang_type, + size_t idx, + lldb::TemplateArgumentKind &kind) + { + return GetTemplateArgument(getASTContext(), clang_type, idx, kind); + } + + static size_t + GetNumTemplateArguments (clang::ASTContext *ast, + lldb::clang_type_t clang_type); + + static lldb::clang_type_t + GetTemplateArgument (clang::ASTContext *ast, + lldb::clang_type_t clang_type, + size_t idx, + lldb::TemplateArgumentKind &kind); + //------------------------------------------------------------------ // clang::TagType //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=149658&r1=149657&r2=149658&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Thu Feb 2 19:30:30 2012 @@ -577,6 +577,19 @@ eTypeClassAny = (0xffffffffu) }TypeClass; + typedef enum TemplateArgumentKind + { + eTemplateArgumentKindNull = 0, + eTemplateArgumentKindType, + eTemplateArgumentKindDeclaration, + eTemplateArgumentKindIntegral, + eTemplateArgumentKindTemplate, + eTemplateArgumentKindTemplateExpansion, + eTemplateArgumentKindExpression, + eTemplateArgumentKindPack + + } TemplateArgumentKind; + } // namespace lldb Modified: lldb/trunk/scripts/Python/interface/SBType.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBType.i?rev=149658&r1=149657&r2=149658&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBType.i (original) +++ lldb/trunk/scripts/Python/interface/SBType.i Thu Feb 2 19:30:30 2012 @@ -191,6 +191,15 @@ lldb::TypeClass GetTypeClass (); + uint32_t + GetNumberOfTemplateArguments (); + + lldb::SBType + GetTemplateArgumentType (uint32_t idx); + + lldb::TemplateArgumentKind + GetTemplateArgumentKind (uint32_t idx); + %pythoncode %{ __swig_getmethods__["name"] = GetName if _newclass: x = property(GetName, None) Modified: lldb/trunk/source/API/SBType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=149658&r1=149657&r2=149658&view=diff ============================================================================== --- lldb/trunk/source/API/SBType.cpp (original) +++ lldb/trunk/source/API/SBType.cpp Thu Feb 2 19:30:30 2012 @@ -437,6 +437,50 @@ return lldb::eTypeClassInvalid; } +uint32_t +SBType::GetNumberOfTemplateArguments () +{ + if (IsValid()) + { + return ClangASTContext::GetNumTemplateArguments (m_opaque_sp->GetASTContext(), + m_opaque_sp->GetOpaqueQualType()); + } + return 0; +} + +lldb::SBType +SBType::GetTemplateArgumentType (uint32_t idx) +{ + if (IsValid()) + { + TemplateArgumentKind kind = eTemplateArgumentKindNull; + return SBType(ClangASTType(m_opaque_sp->GetASTContext(), + ClangASTContext::GetTemplateArgument(m_opaque_sp->GetASTContext(), + m_opaque_sp->GetOpaqueQualType(), + idx, + kind))); + } + return SBType(); +} + + +lldb::TemplateArgumentKind +SBType::GetTemplateArgumentKind (uint32_t idx) +{ + TemplateArgumentKind kind = eTemplateArgumentKindNull; + if (IsValid()) + { + ClangASTContext::GetTemplateArgument(m_opaque_sp->GetASTContext(), + m_opaque_sp->GetOpaqueQualType(), + idx, + kind); + } + return kind; +} + + + + SBTypeList::SBTypeList() : m_opaque_ap(new TypeListImpl()) { @@ -622,4 +666,3 @@ { return *m_opaque_ap.get(); } - Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=149658&r1=149657&r2=149658&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Thu Feb 2 19:30:30 2012 @@ -326,7 +326,7 @@ // embedded we don't know we should be feeding input to the embedded // interpreter or to the python sys.stdin. We also don't want to let python // play with the real stdin from this process, so we need to close it... - run_string.PutCString ("; sys.stdin.close()"); + //run_string.PutCString ("; sys.stdin.close()"); run_string.PutCString ("')"); PyRun_SimpleString (run_string.GetData()); Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=149658&r1=149657&r2=149658&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Feb 2 19:30:30 2012 @@ -2499,6 +2499,111 @@ return objc_method_decl; } +size_t +ClangASTContext::GetNumTemplateArguments (clang::ASTContext *ast, clang_type_t clang_type) +{ + if (clang_type) + { + QualType qual_type (QualType::getFromOpaquePtr(clang_type)); + + const clang::Type::TypeClass type_class = qual_type->getTypeClass(); + switch (type_class) + { + case clang::Type::Record: + if (GetCompleteQualType (ast, qual_type)) + { + const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); + if (cxx_record_decl) + { + const ClassTemplateSpecializationDecl *template_decl = dyn_cast(cxx_record_decl); + if (template_decl) + return template_decl->getTemplateArgs().size(); + } + } + break; + + case clang::Type::Typedef: + return ClangASTContext::GetNumTemplateArguments (ast, cast(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); + default: + break; + } + } + return 0; +} + +clang_type_t +ClangASTContext::GetTemplateArgument (clang::ASTContext *ast, clang_type_t clang_type, size_t arg_idx, lldb::TemplateArgumentKind &kind) +{ + if (clang_type) + { + QualType qual_type (QualType::getFromOpaquePtr(clang_type)); + + const clang::Type::TypeClass type_class = qual_type->getTypeClass(); + switch (type_class) + { + case clang::Type::Record: + if (GetCompleteQualType (ast, qual_type)) + { + const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); + if (cxx_record_decl) + { + const ClassTemplateSpecializationDecl *template_decl = dyn_cast(cxx_record_decl); + if (template_decl && arg_idx < template_decl->getTemplateArgs().size()) + { + const TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx]; + switch (template_arg.getKind()) + { + case clang::TemplateArgument::Null: + kind = eTemplateArgumentKindNull; + return NULL; + + case clang::TemplateArgument::Type: + kind = eTemplateArgumentKindType; + return template_arg.getAsType().getAsOpaquePtr(); + + case clang::TemplateArgument::Declaration: + kind = eTemplateArgumentKindDeclaration; + return NULL; + + case clang::TemplateArgument::Integral: + kind = eTemplateArgumentKindIntegral; + return template_arg.getIntegralType().getAsOpaquePtr(); + + case clang::TemplateArgument::Template: + kind = eTemplateArgumentKindTemplate; + return NULL; + + case clang::TemplateArgument::TemplateExpansion: + kind = eTemplateArgumentKindTemplateExpansion; + return NULL; + + case clang::TemplateArgument::Expression: + kind = eTemplateArgumentKindExpression; + return NULL; + + case clang::TemplateArgument::Pack: + kind = eTemplateArgumentKindPack; + return NULL; + + default: + assert (!"Unhandled TemplateArgument::ArgKind"); + kind = eTemplateArgumentKindNull; + return NULL; + } + } + } + } + break; + + case clang::Type::Typedef: + return ClangASTContext::GetTemplateArgument (ast, cast(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), arg_idx, kind); + default: + break; + } + } + kind = eTemplateArgumentKindNull; + return NULL; +} uint32_t ClangASTContext::GetTypeInfo From granata.enrico at gmail.com Thu Feb 2 19:41:25 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Fri, 03 Feb 2012 01:41:25 -0000 Subject: [Lldb-commits] [lldb] r149661 - in /lldb/trunk: include/lldb/Target/CPPLanguageRuntime.h source/Target/CPPLanguageRuntime.cpp Message-ID: <20120203014125.74ED92A6C12C@llvm.org> Author: enrico Date: Thu Feb 2 19:41:25 2012 New Revision: 149661 URL: http://llvm.org/viewvc/llvm-project?rev=149661&view=rev Log: Adding support for an "equivalents map". This can be useful when compilers emit multiple, different names for the same actual type. In such scenarios, one of the type names can actually be found during a type lookup, while the others are just aliases. This can cause issues when trying to work with these aliased names and being unable to resolve them to an actual type (e.g. getting an SBType for the aliased name). Currently, no code is using this feature, since we can hopefully rely on the new template support in SBType to get the same stuff done, but the support is there just in case it turns out to be useful for some future need. Modified: lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h lldb/trunk/source/Target/CPPLanguageRuntime.cpp Modified: lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h?rev=149661&r1=149660&r2=149661&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h (original) +++ lldb/trunk/include/lldb/Target/CPPLanguageRuntime.h Thu Feb 2 19:41:25 2012 @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include // Other libraries and framework includes // Project includes #include "lldb/Core/PluginInterface.h" @@ -50,6 +51,14 @@ static bool StripNamespacesFromVariableName (const char *name, const char *&base_name_start, const char *&base_name_end); + + // in some cases, compilers will output different names for one same type. when tht happens, it might be impossible + // to construct SBType objects for a valid type, because the name that is available is not the same as the name that + // can be used as a search key in FindTypes(). the equivalents map here is meant to return possible alternative names + // for a type through which a search can be conducted. Currently, this is only enabled for C++ but can be extended + // to ObjC or other languages if necessary + static uint32_t + FindEquivalentNames(ConstString type_name, std::vector& equivalents); protected: //------------------------------------------------------------------ Modified: lldb/trunk/source/Target/CPPLanguageRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/CPPLanguageRuntime.cpp?rev=149661&r1=149660&r2=149661&view=diff ============================================================================== --- lldb/trunk/source/Target/CPPLanguageRuntime.cpp (original) +++ lldb/trunk/source/Target/CPPLanguageRuntime.cpp Thu Feb 2 19:41:25 2012 @@ -8,12 +8,147 @@ //===----------------------------------------------------------------------===// #include "lldb/Target/CPPLanguageRuntime.h" + #include "lldb/Core/PluginManager.h" +#include "lldb/Core/UniqueCStringMap.h" #include "lldb/Target/ExecutionContext.h" using namespace lldb; using namespace lldb_private; +class CPPRuntimeEquivalents +{ +public: + CPPRuntimeEquivalents () + { + + m_impl.Append(ConstString("std::basic_string, std::allocator >").AsCString(), ConstString("basic_string")); + m_impl.Append(ConstString("class std::basic_string, class std::allocator >").AsCString(), ConstString("basic_string")); + + // these two (with a prefixed std::) occur when c++stdlib string class occurs as a template argument in some STL container + m_impl.Append(ConstString("std::basic_string, std::allocator >").AsCString(), ConstString("std::basic_string")); + m_impl.Append(ConstString("class std::basic_string, class std::allocator >").AsCString(), ConstString("std::asic_string")); + + m_impl.Sort(); + } + + void + Add (ConstString& type_name, + ConstString& type_equivalent) + { + m_impl.Insert(type_name.AsCString(), type_equivalent); + } + + uint32_t + FindExactMatches (ConstString& type_name, + std::vector& equivalents) + { + + uint32_t count = 0; + + for (ImplData match = m_impl.FindFirstValueForName(type_name.AsCString()); + match != NULL; + match = m_impl.FindNextValueForName(match)) + { + equivalents.push_back(match->value); + count++; + } + + return count; + } + + // partial matches can occur when a name with equivalents is a template argument. + // e.g. we may have "class Foo" be a match for "struct Bar". if we have a typename + // such as "class Templatized" we want this to be replaced with + // "class Templatized". Since partial matching is time consuming + // once we get a partial match, we add it to the exact matches list for faster retrieval + uint32_t + FindPartialMatches (ConstString& type_name, + std::vector& equivalents) + { + + uint32_t count = 0; + + const char* type_name_cstr = type_name.AsCString(); + + size_t items_count = m_impl.GetSize(); + + for (size_t item = 0; item < items_count; item++) + { + const char* key_cstr = m_impl.GetCStringAtIndex(item); + if ( strstr(type_name_cstr,key_cstr) ) + { + count += AppendReplacements(type_name_cstr, + key_cstr, + equivalents); + } + } + + return count; + + } + +private: + + std::string& replace (std::string& target, + std::string& pattern, + std::string& with) + { + size_t pos; + size_t pattern_len = pattern.size(); + + while ( (pos = target.find(pattern)) != std::string::npos ) + target.replace(pos, pattern_len, with); + + return target; + } + + uint32_t + AppendReplacements (const char* original, + const char *matching_key, + std::vector& equivalents) + { + + std::string matching_key_str(matching_key); + ConstString original_const(original); + + uint32_t count = 0; + + for (ImplData match = m_impl.FindFirstValueForName(matching_key); + match != NULL; + match = m_impl.FindNextValueForName(match)) + { + std::string target(original); + std::string equiv_class(match->value.AsCString()); + + replace (target, matching_key_str, equiv_class); + + ConstString target_const(target.c_str()); + +// you will most probably want to leave this off since it might make this map grow indefinitely +#ifdef ENABLE_CPP_EQUIVALENTS_MAP_TO_GROW + Add(original_const, target_const); +#endif + equivalents.push_back(target_const); + + count++; + } + + return count; + } + + typedef UniqueCStringMap Impl; + typedef const Impl::Entry* ImplData; + Impl m_impl; +}; + +static CPPRuntimeEquivalents& +GetEquivalentsMap () +{ + static CPPRuntimeEquivalents g_equivalents_map; + return g_equivalents_map; +} + //---------------------------------------------------------------------- // Destructor //---------------------------------------------------------------------- @@ -118,3 +253,19 @@ return StripNamespacesFromVariableName (name, base_name_start, base_name_end); } + +uint32_t +CPPLanguageRuntime::FindEquivalentNames(ConstString type_name, std::vector& equivalents) +{ + uint32_t count = GetEquivalentsMap().FindExactMatches(type_name, equivalents); + + bool might_have_partials= + ( count == 0 ) // if we have a full name match just use it + && (strchr(type_name.AsCString(), '<') != NULL // we should only have partial matches when templates are involved, check that we have + && strchr(type_name.AsCString(), '>') != NULL); // angle brackets in the type_name before trying to scan for partial matches + + if ( might_have_partials ) + count = GetEquivalentsMap().FindPartialMatches(type_name, equivalents); + + return count; +} From gclayton at apple.com Thu Feb 2 21:22:53 2012 From: gclayton at apple.com (Greg Clayton) Date: Fri, 03 Feb 2012 03:22:53 -0000 Subject: [Lldb-commits] [lldb] r149665 - in /lldb/trunk/scripts/Python/interface: SBModule.i SBProcess.i SBTarget.i SBThread.i Message-ID: <20120203032253.B41D72A6C12C@llvm.org> Author: gclayton Date: Thu Feb 2 21:22:53 2012 New Revision: 149665 URL: http://llvm.org/viewvc/llvm-project?rev=149665&view=rev Log: Cleaned up the documentation strings for many helper objects and added lldb.SBModule.section and lldb.SBModule.sections property access. Modified: lldb/trunk/scripts/Python/interface/SBModule.i lldb/trunk/scripts/Python/interface/SBProcess.i lldb/trunk/scripts/Python/interface/SBTarget.i lldb/trunk/scripts/Python/interface/SBThread.i Modified: lldb/trunk/scripts/Python/interface/SBModule.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBModule.i?rev=149665&r1=149664&r2=149665&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBModule.i (original) +++ lldb/trunk/scripts/Python/interface/SBModule.i Thu Feb 2 21:22:53 2012 @@ -248,7 +248,7 @@ %pythoncode %{ class symbols_access(object): - re_type = type(re.compile('.')) + re_compile_type = type(re.compile('.')) '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' def __init__(self, sbmodule): self.sbmodule = sbmodule @@ -259,7 +259,7 @@ return 0 def __getitem__(self, key): - count = self.sbmodule.GetNumSymbols() + count = len(self) if type(key) is int: if key < count: return self.sbmodule.GetSymbolAtIndex(key) @@ -269,9 +269,8 @@ symbol = self.sbmodule.GetSymbolAtIndex(idx) if symbol.name == key or symbol.mangled == key: matches.append(symbol) - if len(matches): - return matches - elif isinstance(key, self.re_type): + return matches + elif isinstance(key, self.re_compile_type): matches = [] for idx in range(count): symbol = self.sbmodule.GetSymbolAtIndex(idx) @@ -288,29 +287,83 @@ re_match = key.search(mangled) if re_match: matches.append(symbol) - if len(matches): - return matches + return matches else: print "error: unsupported item type: %s" % type(key) return None def get_symbols_access_object(self): - '''An accessor function that retuns a symbols_access() object which allows lazy module array access.''' + '''An accessor function that returns a symbols_access() object which allows lazy symbol access from a lldb.SBModule object.''' return self.symbols_access (self) def get_symbols_array(self): - '''An accessor function that retuns an array object that contains all modules in this target object.''' + '''An accessor function that returns a list() that contains all symbols in a lldb.SBModule object.''' symbols = [] - for idx in range(self.GetNumSymbols()): + for idx in range(self.num_symbols): symbols.append(self.GetSymbolAtIndex(idx)) return symbols + class sections_access(object): + re_compile_type = type(re.compile('.')) + '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.''' + def __init__(self, sbmodule): + self.sbmodule = sbmodule + + def __len__(self): + if self.sbmodule: + return self.sbmodule.GetNumSections() + return 0 + + def __getitem__(self, key): + count = len(self) + if type(key) is int: + if key < count: + return self.sbmodule.GetSectionAtIndex(key) + elif type(key) is str: + matches = [] + for idx in range(count): + section = self.sbmodule.GetSectionAtIndex(idx) + if section.name == key: + matches.append(section) + return matches + elif isinstance(key, self.re_compile_type): + matches = [] + for idx in range(count): + section = self.sbmodule.GetSectionAtIndex(idx) + name = section.name + if name: + re_match = key.search(name) + if re_match: + matches.append(section) + return matches + else: + print "error: unsupported item type: %s" % type(key) + return None + + def get_sections_access_object(self): + '''An accessor function that returns a sections_access() object which allows lazy section array access.''' + return self.sections_access (self) + + def get_sections_array(self): + '''An accessor function that returns an array object that contains all sections in this module object.''' + if not hasattr(self, 'sections'): + self.sections = [] + for idx in range(self.num_sections): + self.sections.append(self.GetSectionAtIndex(idx)) + return self.sections + __swig_getmethods__["symbols"] = get_symbols_array if _newclass: x = property(get_symbols_array, None) __swig_getmethods__["symbol"] = get_symbols_access_object if _newclass: x = property(get_symbols_access_object, None) + + __swig_getmethods__["sections"] = get_sections_array + if _newclass: x = property(get_sections_array, None) + __swig_getmethods__["section"] = get_sections_access_object + if _newclass: x = property(get_sections_access_object, None) + def get_uuid(self): return uuid.UUID (self.GetUUIDString()) Modified: lldb/trunk/scripts/Python/interface/SBProcess.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBProcess.i?rev=149665&r1=149664&r2=149665&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBProcess.i (original) +++ lldb/trunk/scripts/Python/interface/SBProcess.i Thu Feb 2 21:22:53 2012 @@ -309,7 +309,7 @@ return True return False - class thread_array_access(object): + class threads_access(object): '''A helper object that will lazily hand out thread for a process when supplied an index.''' def __init__(self, sbprocess): self.sbprocess = sbprocess @@ -323,12 +323,12 @@ return self.sbprocess.GetThreadAtIndex(key) return None - def get_thread_array_access_object(self): - '''An accessor function that retuns a thread_array_access() object which allows lazy thread array access.''' - return self.thread_array_access (self) + def get_threads_access_object(self): + '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.''' + return self.threads_access (self) def get_process_thread_list(self): - '''An accessor function that retuns an array object that contains all threads in this process object.''' + '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.''' threads = [] for idx in range(self.GetNumThreads()): threads.append(GetThreadAtIndex(idx)) @@ -337,8 +337,8 @@ __swig_getmethods__["threads"] = get_process_thread_list if _newclass: x = property(get_process_thread_list, None) - __swig_getmethods__["thread"] = get_thread_array_access_object - if _newclass: x = property(get_thread_array_access_object, None) + __swig_getmethods__["thread"] = get_threads_access_object + if _newclass: x = property(get_threads_access_object, None) __swig_getmethods__["is_alive"] = __get_is_alive__ if _newclass: x = property(__get_is_alive__, None) Modified: lldb/trunk/scripts/Python/interface/SBTarget.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=149665&r1=149664&r2=149665&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBTarget.i (original) +++ lldb/trunk/scripts/Python/interface/SBTarget.i Thu Feb 2 21:22:53 2012 @@ -538,11 +538,11 @@ return None def get_modules_access_object(self): - '''An accessor function that retuns a modules_access() object which allows lazy module array access.''' + '''An accessor function that returns a modules_access() object which allows lazy module access from a lldb.SBTarget object.''' return self.modules_access (self) def get_modules_array(self): - '''An accessor function that retuns an array object that contains all modules in this target object.''' + '''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.''' modules = [] for idx in range(self.GetNumModules()): modules.append(self.GetModuleAtIndex(idx)) Modified: lldb/trunk/scripts/Python/interface/SBThread.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBThread.i?rev=149665&r1=149664&r2=149665&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBThread.i (original) +++ lldb/trunk/scripts/Python/interface/SBThread.i Thu Feb 2 21:22:53 2012 @@ -175,7 +175,7 @@ GetDescription (lldb::SBStream &description) const; %pythoncode %{ - class frame_array_access(object): + class frames_access(object): '''A helper object that will lazily hand out frames for a thread when supplied an index.''' def __init__(self, sbthread): self.sbthread = sbthread @@ -190,12 +190,12 @@ return self.sbthread.GetFrameAtIndex(key) return None - def get_frame_array_access_object(self): - '''An accessor function that retuns a frame_array_access() object which allows lazy frame array access.''' - return self.frame_array_access (self) + def get_frames_access_object(self): + '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.''' + return self.frames_access (self) def get_thread_frames(self): - '''An accessor function that retuns an array object that contains all frames in this thread object.''' + '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.''' frames = [] for frame in self: frames.append(frame) @@ -219,8 +219,8 @@ __swig_getmethods__["frames"] = get_thread_frames if _newclass: x = property(get_thread_frames, None) - __swig_getmethods__["frame"] = get_frame_array_access_object - if _newclass: x = property(get_frame_array_access_object, None) + __swig_getmethods__["frame"] = get_frames_access_object + if _newclass: x = property(get_frames_access_object, None) __swig_getmethods__["name"] = GetName if _newclass: x = property(GetName, None) From gclayton at apple.com Thu Feb 2 23:34:10 2012 From: gclayton at apple.com (Greg Clayton) Date: Fri, 03 Feb 2012 05:34:10 -0000 Subject: [Lldb-commits] [lldb] r149673 - in /lldb/trunk: include/lldb/Core/ValueObject.h include/lldb/Core/ValueObjectDynamicValue.h scripts/Python/interface/SBType.i source/API/SBValue.cpp source/Core/ValueObject.cpp source/Core/ValueObjectDynamicValue.cpp Message-ID: <20120203053410.B17772A6C12C@llvm.org> Author: gclayton Date: Thu Feb 2 23:34:10 2012 New Revision: 149673 URL: http://llvm.org/viewvc/llvm-project?rev=149673&view=rev Log: Fixed casting in the lldb::SBValue::Cast(SBType) function. Modified: lldb/trunk/include/lldb/Core/ValueObject.h lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h lldb/trunk/scripts/Python/interface/SBType.i lldb/trunk/source/API/SBValue.cpp lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Modified: lldb/trunk/include/lldb/Core/ValueObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=149673&r1=149672&r2=149673&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObject.h (original) +++ lldb/trunk/include/lldb/Core/ValueObject.h Thu Feb 2 23:34:10 2012 @@ -774,6 +774,9 @@ } virtual lldb::ValueObjectSP + Cast (const ClangASTType &clang_ast_type); + + virtual lldb::ValueObjectSP CastPointerType (const char *name, ClangASTType &ast_type); Modified: lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h?rev=149673&r1=149672&r2=149673&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h Thu Feb 2 23:34:10 2012 @@ -15,9 +15,85 @@ // Other libraries and framework includes // Project includes #include "lldb/Core/ValueObject.h" +#include "lldb/Symbol/ClangASTType.h" namespace lldb_private { + class ValueObjectCast : public ValueObject + { + public: + virtual + ~ValueObjectCast(); + + virtual size_t + GetByteSize(); + + virtual clang::ASTContext * + GetClangAST (); + + virtual lldb::clang_type_t + GetClangType (); + + virtual ConstString + GetTypeName(); + + virtual uint32_t + CalculateNumChildren(); + + virtual lldb::ValueType + GetValueType() const; + + virtual bool + IsInScope (); + + virtual bool + IsDynamic () + { + return true; + } + + virtual ValueObject * + GetParent() + { + if (m_parent) + return m_parent->GetParent(); + else + return NULL; + } + + virtual const ValueObject * + GetParent() const + { + if (m_parent) + return m_parent->GetParent(); + else + return NULL; + } + + virtual lldb::ValueObjectSP + GetStaticValue () + { + return m_parent->GetSP(); + } + + protected: + virtual bool + UpdateValue (); + + ClangASTType m_cast_type; + + private: + friend class ValueObject; + ValueObjectCast (ValueObject &parent, + const ConstString &name, + const ClangASTType &cast_type); + + //------------------------------------------------------------------ + // For ValueObject only + //------------------------------------------------------------------ + DISALLOW_COPY_AND_ASSIGN (ValueObjectCast); + }; + //---------------------------------------------------------------------- // A ValueObject that represents memory at a given address, viewed as some // set lldb type. Modified: lldb/trunk/scripts/Python/interface/SBType.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBType.i?rev=149673&r1=149672&r2=149673&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBType.i (original) +++ lldb/trunk/scripts/Python/interface/SBType.i Thu Feb 2 23:34:10 2012 @@ -201,6 +201,15 @@ GetTemplateArgumentKind (uint32_t idx); %pythoncode %{ + def template_arg_array(self): + num_args = self.num_template_args + if num_args: + template_args = [] + for i in range(num_args): + template_args.append(self.GetTemplateArgumentType(i)) + return template_args + return None + __swig_getmethods__["name"] = GetName if _newclass: x = property(GetName, None) @@ -222,9 +231,16 @@ __swig_getmethods__["num_vbases"] = GetNumberOfVirtualBaseClasses if _newclass: x = property(GetNumberOfVirtualBaseClasses, None) + __swig_getmethods__["num_template_args"] = GetNumberOfTemplateArguments + if _newclass: x = property(GetNumberOfTemplateArguments, None) + + __swig_getmethods__["template_args"] = template_arg_array + if _newclass: x = property(template_arg_array, None) + __swig_getmethods__["class"] = GetTypeClass if _newclass: x = property(GetTypeClass, None) - %} + + %} }; Modified: lldb/trunk/source/API/SBValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=149673&r1=149672&r2=149673&view=diff ============================================================================== --- lldb/trunk/source/API/SBValue.cpp (original) +++ lldb/trunk/source/API/SBValue.cpp Thu Feb 2 23:34:10 2012 @@ -378,8 +378,8 @@ SBValue::Cast (SBType type) { lldb::SBValue sb_value; - if (m_opaque_sp) - sb_value = CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type); + if (m_opaque_sp && type.IsValid()) + *sb_value = m_opaque_sp->Cast(type.ref().GetClangASTType()); return sb_value; } Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=149673&r1=149672&r2=149673&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Thu Feb 2 23:34:10 2012 @@ -3429,6 +3429,12 @@ return m_addr_of_valobj_sp; } +ValueObjectSP +ValueObject::Cast (const ClangASTType &clang_ast_type) +{ + ValueObjectSP valobj_sp(new ValueObjectCast (*this, GetName(), clang_ast_type)); + return valobj_sp; +} ValueObjectSP ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) Modified: lldb/trunk/source/Core/ValueObjectDynamicValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectDynamicValue.cpp?rev=149673&r1=149672&r2=149673&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectDynamicValue.cpp (original) +++ lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Thu Feb 2 23:34:10 2012 @@ -34,6 +34,107 @@ using namespace lldb_private; + +ValueObjectCast::ValueObjectCast +( + ValueObject &parent, + const ConstString &name, + const ClangASTType &cast_type +) : + ValueObject(parent), + m_cast_type (cast_type) +{ + SetName (name); + m_value.SetContext (Value::eContextTypeClangType, cast_type.GetOpaqueQualType()); +} + +ValueObjectCast::~ValueObjectCast() +{ +} + +lldb::clang_type_t +ValueObjectCast::GetClangType () +{ + return m_cast_type.GetOpaqueQualType(); +} + +ConstString +ValueObjectCast::GetTypeName() +{ + return ClangASTType::GetConstTypeName (GetClangType()); +} + +uint32_t +ValueObjectCast::CalculateNumChildren() +{ + return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true); +} + +clang::ASTContext * +ValueObjectCast::GetClangAST () +{ + return m_cast_type.GetASTContext(); +} + +size_t +ValueObjectCast::GetByteSize() +{ + return m_value.GetValueByteSize(GetClangAST(), NULL); +} + +lldb::ValueType +ValueObjectCast::GetValueType() const +{ + // Let our parent answer global, local, argument, etc... + return m_parent->GetValueType(); +} + +bool +ValueObjectCast::UpdateValue () +{ + SetValueIsValid (false); + m_error.Clear(); + + if (m_parent->UpdateValueIfNeeded(false)) + { + Value old_value(m_value); + m_update_point.SetUpdated(); + m_value = m_parent->GetValue(); + m_value.SetContext (Value::eContextTypeClangType, GetClangType()); + SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren()); + if (ClangASTContext::IsAggregateType (GetClangType())) + { + // this value object represents an aggregate type whose + // children have values, but this object does not. So we + // say we are changed if our location has changed. + SetValueDidChange (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar()); + } + ExecutionContext exe_ctx (GetExecutionContextScope()); + m_error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule()); + SetValueDidChange (m_parent->GetValueDidChange()); + return true; + } + + // The dynamic value failed to get an error, pass the error along + if (m_error.Success() && m_parent->GetError().Fail()) + m_error = m_parent->GetError(); + SetValueIsValid (false); + return false; +} + + + +bool +ValueObjectCast::IsInScope () +{ + return m_parent->IsInScope(); +} + +//---------------------------------------------------------------------- + + + + ValueObjectDynamicValue::ValueObjectDynamicValue (ValueObject &parent, lldb::DynamicValueType use_dynamic) : ValueObject(parent), m_address (), From gclayton at apple.com Fri Feb 3 01:02:38 2012 From: gclayton at apple.com (Greg Clayton) Date: Fri, 03 Feb 2012 07:02:38 -0000 Subject: [Lldb-commits] [lldb] r149684 - in /lldb/trunk: include/lldb/API/SBFrame.h scripts/Python/interface/SBFrame.i scripts/Python/interface/SBValue.i scripts/Python/interface/SBValueList.i scripts/Python/python-extensions.swig source/API/SBFrame.cpp Message-ID: <20120203070238.3F4FD2A6C12C@llvm.org> Author: gclayton Date: Fri Feb 3 01:02:37 2012 New Revision: 149684 URL: http://llvm.org/viewvc/llvm-project?rev=149684&view=rev Log: Expose more convenience functionality in the python classes. lldb.SBValueList now exposes the len() method and also allows item access: lldb.SBValueList[] - where is an integer index into the list, returns a single lldb.SBValue which might be empty if the index is out of range lldb.SBValueList[] - where is the name to look for, returns a list() of lldb.SBValue objects with any matching values (the list might be empty if nothing matches) lldb.SBValueList[] - where is a compiles regular expression, returns a list of lldb.SBValue objects for containing any matches or a empty list if nothing matches lldb.SBFrame now exposes: lldb.SBFrame.variables => SBValueList of all variables that are in scope lldb.SBFrame.vars => see lldb.SBFrame.variables lldb.SBFrame.locals => SBValueList of all variables that are locals in the current frame lldb.SBFrame.arguments => SBValueList of all variables that are arguments in the current frame lldb.SBFrame.args => see lldb.SBFrame.arguments lldb.SBFrame.statics => SBValueList of all static variables lldb.SBFrame.registers => SBValueList of all registers for the current frame lldb.SBFrame.regs => see lldb.SBFrame.registers Combine any of the above properties with the new lldb.SBValueList functionality and now you can do: y = lldb.frame.vars['rect.origin.y'] or vars = lldb.frame.vars for i in range len(vars): print vars[i] Also expose "lldb.SBFrame.var()" where can be en expression path for any variable or child within the variable. This makes it easier to get a value from the current frame like "rect.origin.y". The resulting value is also not a constant result as expressions will return, but a live value that will continue to track the current value for the variable expression path. lldb.SBValue now exposes: lldb.SBValue.unsigned => unsigned integer for the value lldb.SBValue.signed => a signed integer for the value Modified: lldb/trunk/include/lldb/API/SBFrame.h lldb/trunk/scripts/Python/interface/SBFrame.i lldb/trunk/scripts/Python/interface/SBValue.i lldb/trunk/scripts/Python/interface/SBValueList.i lldb/trunk/scripts/Python/python-extensions.swig lldb/trunk/source/API/SBFrame.cpp Modified: lldb/trunk/include/lldb/API/SBFrame.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=149684&r1=149683&r2=149684&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFrame.h (original) +++ lldb/trunk/include/lldb/API/SBFrame.h Fri Feb 3 01:02:37 2012 @@ -165,6 +165,20 @@ lldb::SBValue FindVariable (const char *var_name, lldb::DynamicValueType use_dynamic); + // Find a value for a variable expression path like "rect.origin.x" or + // "pt_ptr->x", "*self", "*this->obj_ptr". The returned value is _not_ + // and expression result and is not a constant object like + // SBFrame::EvaluateExpression(...) returns, but a child object of + // the variable value. + lldb::SBValue + GetValueForVariablePath (const char *var_expr_cstr, + DynamicValueType use_dynamic); + + /// The version that doesn't supply a 'use_dynamic' value will use the + /// target's default. + lldb::SBValue + GetValueForVariablePath (const char *var_path); + /// Find variables, register sets, registers, or persistent variables using /// the frame as the scope. /// Modified: lldb/trunk/scripts/Python/interface/SBFrame.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFrame.i?rev=149684&r1=149683&r2=149684&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBFrame.i (original) +++ lldb/trunk/scripts/Python/interface/SBFrame.i Fri Feb 3 01:02:37 2012 @@ -203,6 +203,34 @@ FindVariable (const char *var_name, lldb::DynamicValueType use_dynamic); %feature("docstring", " + /// Get a lldb.SBValue for a variable path. + /// + /// Variable paths can include access to pointer or instance members: + /// rect_ptr->origin.y + /// pt.x + /// Pointer dereferences: + /// *this->foo_ptr + /// **argv + /// Address of: + /// &pt + /// &my_array[3].x + /// Array accesses and treating pointers as arrays: + /// int_array[1] + /// pt_ptr[22].x + /// + /// Unlike EvaluateExpression() which returns lldb.SBValue objects + /// with constant copies of the values at the time of evaluation, + /// the result of this function is a value that will continue to + /// track the current value of the value as execution progresses + /// in the current frame. + ") GetValueForVariablePath; + lldb::SBValue + GetValueForVariablePath (const char *var_path); + + lldb::SBValue + GetValueForVariablePath (const char *var_path, lldb::DynamicValueType use_dynamic); + + %feature("docstring", " /// Find variables, register sets, registers, or persistent variables using /// the frame as the scope. /// @@ -219,6 +247,23 @@ GetDescription (lldb::SBStream &description); %pythoncode %{ + def get_all_variables(self): + return self.GetVariables(True,True,True,True) + + def get_arguments(self): + return self.GetVariables(True,False,False,False) + + def get_locals(self): + return self.GetVariables(False,True,False,False) + + def get_statics(self): + return self.GetVariables(False,False,True,False) + + def var(self, var_expr_path): + '''Calls through to lldb.SBFrame.GetValueForVariablePath() and returns + a value that represents the variable expression path''' + return self.GetValueForVariablePath(var_expr_path) + __swig_getmethods__["pc"] = GetPC __swig_setmethods__["pc"] = SetPC if _newclass: x = property(GetPC, SetPC) @@ -265,6 +310,30 @@ __swig_getmethods__["idx"] = GetFrameID if _newclass: x = property(GetFrameID, None) + __swig_getmethods__["variables"] = get_all_variables + if _newclass: x = property(get_all_variables, None) + + __swig_getmethods__["vars"] = get_all_variables + if _newclass: x = property(get_all_variables, None) + + __swig_getmethods__["locals"] = get_locals + if _newclass: x = property(get_locals, None) + + __swig_getmethods__["args"] = get_arguments + if _newclass: x = property(get_arguments, None) + + __swig_getmethods__["arguments"] = get_arguments + if _newclass: x = property(get_arguments, None) + + __swig_getmethods__["statics"] = get_statics + if _newclass: x = property(get_statics, None) + + __swig_getmethods__["registers"] = GetRegisters + if _newclass: x = property(GetRegisters, None) + + __swig_getmethods__["regs"] = GetRegisters + if _newclass: x = property(GetRegisters, None) + %} }; Modified: lldb/trunk/scripts/Python/interface/SBValue.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBValue.i?rev=149684&r1=149683&r2=149684&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBValue.i (original) +++ lldb/trunk/scripts/Python/interface/SBValue.i Fri Feb 3 01:02:37 2012 @@ -436,6 +436,19 @@ __swig_getmethods__["num_children"] = GetNumChildren if _newclass: x = property(GetNumChildren, None) + __swig_getmethods__["unsigned"] = GetValueAsUnsigned + if _newclass: x = property(GetValueAsUnsigned, None) + + __swig_getmethods__["signed"] = GetValueAsSigned + if _newclass: x = property(GetValueAsSigned, None) + + def get_expr_path(self): + s = SBStream() + self.GetExpressionPath (s) + return s.GetData() + + __swig_getmethods__["path"] = get_expr_path + if _newclass: x = property(get_expr_path, None) %} }; Modified: lldb/trunk/scripts/Python/interface/SBValueList.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBValueList.i?rev=149684&r1=149683&r2=149684&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBValueList.i (original) +++ lldb/trunk/scripts/Python/interface/SBValueList.i Fri Feb 3 01:02:37 2012 @@ -96,6 +96,43 @@ lldb::SBValue FindValueObjectByUID (lldb::user_id_t uid); + %pythoncode %{ + def __len__(self): + return self.GetSize() + + def __getitem__(self, key): + count = len(self) + #------------------------------------------------------------ + # Access with "int" to get Nth item in the list + #------------------------------------------------------------ + if type(key) is int: + if key < count: + return self.GetValueAtIndex(key) + #------------------------------------------------------------ + # Access with "str" to get values by name + #------------------------------------------------------------ + elif type(key) is str: + matches = [] + for idx in range(count): + value = self.GetValueAtIndex(idx) + if value.name == key: + matches.append(value) + return matches + #------------------------------------------------------------ + # Match with regex + #------------------------------------------------------------ + elif isinstance(key, type(re.compile('.'))): + matches = [] + for idx in range(count): + value = self.GetValueAtIndex(idx) + re_match = key.search(value.name) + if re_match: + matches.append(value) + return matches + + %} + + }; } // namespace lldb Modified: lldb/trunk/scripts/Python/python-extensions.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=149684&r1=149683&r2=149684&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-extensions.swig (original) +++ lldb/trunk/scripts/Python/python-extensions.swig Fri Feb 3 01:02:37 2012 @@ -324,6 +324,28 @@ return Py_None; } } +%extend lldb::SBValueList { + PyObject *lldb::SBValueList::__repr__ (){ + lldb::SBStream description; + const size_t n = $self->GetSize(); + if (n) + { + for (size_t i=0; iGetValueAtIndex(i).GetDescription(description); + } + else + { + description.Printf(" lldb.SBValueList()"); + } + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + return Py_None; + } +} %extend lldb::SBWatchpoint { PyObject *lldb::SBWatchpoint::__repr__ (){ lldb::SBStream description; Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=149684&r1=149683&r2=149684&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Fri Feb 3 01:02:37 2012 @@ -455,6 +455,39 @@ m_opaque_sp.reset(); } +lldb::SBValue +SBFrame::GetValueForVariablePath (const char *var_path) +{ + SBValue sb_value; + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp) + { + lldb::DynamicValueType use_dynamic = frame_sp->CalculateTarget()->GetPreferDynamicValue(); + sb_value = GetValueForVariablePath (var_path, use_dynamic); + } + return sb_value; +} + +lldb::SBValue +SBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic) +{ + SBValue sb_value; + StackFrameSP frame_sp(GetFrameSP()); + if (frame_sp && var_path && var_path[0]) + { + Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + VariableSP var_sp; + Error error; + ValueObjectSP value_sp (frame_sp->GetValueForVariableExpressionPath (var_path, + use_dynamic, + StackFrame::eExpressionPathOptionCheckPtrVsMember, + var_sp, + error)); + *sb_value = value_sp; + } + return sb_value; +} + SBValue SBFrame::FindVariable (const char *name) { @@ -467,6 +500,7 @@ } return value; } + SBValue SBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) From granata.enrico at gmail.com Fri Feb 3 12:11:52 2012 From: granata.enrico at gmail.com (Enrico Granata) Date: Fri, 03 Feb 2012 18:11:52 -0000 Subject: [Lldb-commits] [lldb] r149700 - in /lldb/trunk: examples/synthetic/gnu_libstdcpp.py test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py Message-ID: <20120203181152.E61032A6C12C@llvm.org> Author: enrico Date: Fri Feb 3 12:11:52 2012 New Revision: 149700 URL: http://llvm.org/viewvc/llvm-project?rev=149700&view=rev Log: Fixing issues where synthetic children providers for STL containers std::list and std::map where not doing their job properly Modified: lldb/trunk/examples/synthetic/gnu_libstdcpp.py lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py Modified: lldb/trunk/examples/synthetic/gnu_libstdcpp.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/synthetic/gnu_libstdcpp.py?rev=149700&r1=149699&r2=149700&view=diff ============================================================================== --- lldb/trunk/examples/synthetic/gnu_libstdcpp.py (original) +++ lldb/trunk/examples/synthetic/gnu_libstdcpp.py Fri Feb 3 12:11:52 2012 @@ -53,33 +53,22 @@ except: return None - def extract_type_name(self,name): - self.type_name = name[16:] - index = 2 - count_of_template = 1 - while index < len(self.type_name): - if self.type_name[index] == '<': - count_of_template = count_of_template + 1 - elif self.type_name[index] == '>': - count_of_template = count_of_template - 1 - elif self.type_name[index] == ',' and count_of_template == 1: - self.type_name = self.type_name[:index] - break - index = index + 1 - self.type_name_nospaces = self.type_name.replace(", ", ",") + def extract_type(self): + list_type = self.valobj.GetType().GetUnqualifiedType() + if list_type.GetNumberOfTemplateArguments() > 0: + data_type = list_type.GetTemplateArgumentType(0) + else: + data_type = None + return data_type def update(self): try: impl = self.valobj.GetChildMemberWithName('_M_impl') node = impl.GetChildMemberWithName('_M_node') - self.extract_type_name(impl.GetType().GetName()) self.node_address = self.valobj.AddressOf().GetValueAsUnsigned(0) self.next = node.GetChildMemberWithName('_M_next') self.prev = node.GetChildMemberWithName('_M_prev') - self.data_type = node.GetTarget().FindFirstType(self.type_name) - # tries to fight against a difference in formatting type names between gcc and clang - if self.data_type.IsValid() == False: - self.data_type = node.GetTarget().FindFirstType(self.type_name_nospaces) + self.data_type = self.extract_type() self.data_size = self.data_type.GetByteSize() except: pass @@ -151,64 +140,52 @@ def __init__(self, valobj, dict): self.valobj = valobj; self.update() + + # we need this function as a temporary workaround for rdar://problem/10801549 + # which prevents us from extracting the std::pair SBType out of the template + # arguments for _Rep_Type _M_t in the map itself - because we have to make up the + # typename and then find it, we may hit the situation were std::string has multiple + # names but only one is actually referenced in the debug information. hence, we need + # to replace the longer versions of std::string with the shorter one in order to be able + # to find the type name + def fixup_class_name(self, class_name): + if class_name == 'std::basic_string, class std::allocator >': + return 'std::basic_string' + if class_name == 'basic_string, class std::allocator >': + return 'std::basic_string' + if class_name == 'std::basic_string, std::allocator >': + return 'std::basic_string' + if class_name == 'basic_string, std::allocator >': + return 'std::basic_string' + return class_name def update(self): try: self.Mt = self.valobj.GetChildMemberWithName('_M_t') self.Mimpl = self.Mt.GetChildMemberWithName('_M_impl') self.Mheader = self.Mimpl.GetChildMemberWithName('_M_header') + + map_arg_0 = str(self.valobj.GetType().GetTemplateArgumentType(0).GetName()) + map_arg_1 = str(self.valobj.GetType().GetTemplateArgumentType(1).GetName()) + + map_arg_0 = self.fixup_class_name(map_arg_0) + map_arg_1 = self.fixup_class_name(map_arg_1) + + map_arg_type = "std::pair': + map_arg_type = map_arg_type + " >" + else: + map_arg_type = map_arg_type + ">" + + self.data_type = self.valobj.GetTarget().FindFirstType(map_arg_type) + # from libstdc++ implementation of _M_root for rbtree self.Mroot = self.Mheader.GetChildMemberWithName('_M_parent') - # the stuff into the tree is actually a std::pair - # life would be much easier if gcc had a coherent way to print out - # template names in debug info - self.expand_clang_type_name() - self.expand_gcc_type_name() - self.data_type = self.Mt.GetTarget().FindFirstType(self.clang_type_name) - if self.data_type.IsValid() == False: - self.data_type = self.Mt.GetTarget().FindFirstType(self.gcc_type_name) self.data_size = self.data_type.GetByteSize() self.skip_size = self.Mheader.GetType().GetByteSize() except: pass - def expand_clang_type_name(self): - type_name = self.Mimpl.GetType().GetName() - index = type_name.find("std::pair<") - type_name = type_name[index+5:] - index = 6 - template_count = 1 - while index < len(type_name): - if type_name[index] == '<': - template_count = template_count + 1 - elif type_name[index] == '>' and template_count == 1: - type_name = type_name[:index+1] - break - elif type_name[index] == '>': - template_count = template_count - 1 - index = index + 1; - self.clang_type_name = type_name - - def expand_gcc_type_name(self): - type_name = self.Mt.GetType().GetName() - index = type_name.find("std::pair<") - type_name = type_name[index+5:] - index = 6 - template_count = 1 - while index < len(type_name): - if type_name[index] == '<': - template_count = template_count + 1 - elif type_name[index] == '>' and template_count == 1: - type_name = type_name[:index+1] - break - elif type_name[index] == '>': - template_count = template_count - 1 - elif type_name[index] == ' ' and template_count == 1 and type_name[index-1] == ',': - type_name = type_name[0:index] + type_name[index+1:] - index = index - 1 - index = index + 1; - self.gcc_type_name = type_name - def num_children(self): try: root_ptr_val = self.node_ptr_value(self.Mroot) Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py?rev=149700&r1=149699&r2=149700&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/list/TestDataFormatterStdList.py Fri Feb 3 12:11:52 2012 @@ -11,16 +11,12 @@ mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "list") - #rdar://problem/10334911 - @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_with_dsym_and_run_command(self): """Test data formatter commands.""" self.buildDsym() self.data_formatter_commands() - #rdar://problem/10334911 - @unittest2.expectedFailure def test_with_dwarf_and_run_command(self): """Test data formatter commands.""" self.buildDwarf() Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py?rev=149700&r1=149699&r2=149700&view=diff ============================================================================== --- lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py (original) +++ lldb/trunk/test/functionalities/data-formatter/data-formatter-stl/map/TestDataFormatterStdMap.py Fri Feb 3 12:11:52 2012 @@ -11,16 +11,12 @@ mydir = os.path.join("functionalities", "data-formatter", "data-formatter-stl", "map") - #rdar://problem/10334911 - @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_with_dsym_and_run_command(self): """Test data formatter commands.""" self.buildDsym() self.data_formatter_commands() - #rdar://problem/10334911 - @unittest2.expectedFailure def test_with_dwarf_and_run_command(self): """Test data formatter commands.""" self.buildDwarf() From johnny.chen at apple.com Fri Feb 3 14:43:00 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 03 Feb 2012 20:43:00 -0000 Subject: [Lldb-commits] [lldb] r149707 - in /lldb/trunk/test: lang/cpp/stl/TestSTL.py lldbtest.py Message-ID: <20120203204300.72E142A6C12C@llvm.org> Author: johnny Date: Fri Feb 3 14:43:00 2012 New Revision: 149707 URL: http://llvm.org/viewvc/llvm-project?rev=149707&view=rev Log: Add test cases for APIs to get template arguments from an SBType. Modified: lldb/trunk/test/lang/cpp/stl/TestSTL.py lldb/trunk/test/lldbtest.py Modified: lldb/trunk/test/lang/cpp/stl/TestSTL.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/stl/TestSTL.py?rev=149707&r1=149706&r2=149707&view=diff ============================================================================== --- lldb/trunk/test/lang/cpp/stl/TestSTL.py (original) +++ lldb/trunk/test/lang/cpp/stl/TestSTL.py Fri Feb 3 14:43:00 2012 @@ -5,6 +5,7 @@ import os, time import unittest2 import lldb +import lldbutil from lldbtest import * class STLTestCase(TestBase): @@ -26,11 +27,24 @@ self.buildDwarf() self.step_stl_exprs() + @python_api_test + def test_SBType_template_aspects_with_dsym(self): + """Test APIs for getting template arguments from a SBType.""" + self.buildDsym() + self.sbtype_template_apis() + + @python_api_test + def test_SBType_template_aspects_with_dwarf(self): + """Test APIs for getting template arguments from a SBType.""" + self.buildDwarf() + self.sbtype_template_apis() + def setUp(self): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break inside main(). - self.line = line_number('main.cpp', '// Set break point at this line.') + self.source = 'main.cpp' + self.line = line_number(self.source, '// Set break point at this line.') def step_stl_exprs(self): """Test some expressions involving STL data types.""" @@ -45,7 +59,7 @@ # rdar://problem/8543077 # test/stl: clang built binaries results in the breakpoint locations = 3, # is this a problem with clang generated debug info? - self.expect("breakpoint set -f main.cpp -l %d" % self.line, + self.expect("breakpoint set -f %s -l %d" % (self.source, self.line), BREAKPOINT_CREATED, startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % self.line) @@ -76,6 +90,53 @@ self.expect('expr associative_array["hello"]', substrs = [' = 2']) + def sbtype_template_apis(self): + """Test APIs for getting template arguments from an SBType.""" + exe = os.path.join(os.getcwd(), 'a.out') + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Create the breakpoint inside function 'main'. + breakpoint = target.BreakpointCreateByLocation(self.source, self.line) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple(None, None, os.getcwd()) + self.assertTrue(process, PROCESS_IS_VALID) + + # Get Frame #0. + self.assertTrue(process.GetState() == lldb.eStateStopped) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition") + frame0 = thread.GetFrameAtIndex(0) + + # Get the type for variable 'associative_array'. + associative_array = frame0.FindVariable('associative_array') + self.DebugSBValue(associative_array) + self.assertTrue(associative_array, VALID_VARIABLE) + map_type = associative_array.GetType() + self.DebugSBType(map_type) + self.assertTrue(map_type, VALID_TYPE) + num_template_args = map_type.GetNumberOfTemplateArguments() + self.assertTrue(num_template_args > 0) + + # We expect the template arguments to contain at least 'string' and 'int'. + expected_types = { 'string': False, 'int': False } + for i in range(num_template_args): + t = map_type.GetTemplateArgumentType(i) + self.DebugSBType(t) + self.assertTrue(t, VALID_TYPE) + name = t.GetName() + if 'string' in name: + expected_types['string'] = True + elif 'int' == name: + expected_types['int'] = True + + # Check that both entries of the dictionary have 'True' as the value. + self.assertTrue(all(expected_types.values())) + if __name__ == '__main__': import atexit Modified: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=149707&r1=149706&r2=149707&view=diff ============================================================================== --- lldb/trunk/test/lldbtest.py (original) +++ lldb/trunk/test/lldbtest.py Fri Feb 3 14:43:00 2012 @@ -196,6 +196,8 @@ VALID_TARGET = "Got a valid target" +VALID_TYPE = "Got a valid type" + VALID_VARIABLE = "Got a valid variable" VARIABLES_DISPLAYED_CORRECTLY = "Variable(s) displayed correctly" From johnny.chen at apple.com Fri Feb 3 14:50:56 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 03 Feb 2012 20:50:56 -0000 Subject: [Lldb-commits] [lldb] r149710 - /lldb/trunk/test/lang/cpp/stl/TestSTL.py Message-ID: <20120203205056.B91932A6C12C@llvm.org> Author: johnny Date: Fri Feb 3 14:50:56 2012 New Revision: 149710 URL: http://llvm.org/viewvc/llvm-project?rev=149710&view=rev Log: Fix typos. Modified: lldb/trunk/test/lang/cpp/stl/TestSTL.py Modified: lldb/trunk/test/lang/cpp/stl/TestSTL.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/stl/TestSTL.py?rev=149710&r1=149709&r2=149710&view=diff ============================================================================== --- lldb/trunk/test/lang/cpp/stl/TestSTL.py (original) +++ lldb/trunk/test/lang/cpp/stl/TestSTL.py Fri Feb 3 14:50:56 2012 @@ -29,13 +29,13 @@ @python_api_test def test_SBType_template_aspects_with_dsym(self): - """Test APIs for getting template arguments from a SBType.""" + """Test APIs for getting template arguments from an SBType.""" self.buildDsym() self.sbtype_template_apis() @python_api_test def test_SBType_template_aspects_with_dwarf(self): - """Test APIs for getting template arguments from a SBType.""" + """Test APIs for getting template arguments from an SBType.""" self.buildDwarf() self.sbtype_template_apis() From johnny.chen at apple.com Fri Feb 3 20:07:34 2012 From: johnny.chen at apple.com (Johnny Chen) Date: Sat, 04 Feb 2012 02:07:34 -0000 Subject: [Lldb-commits] [lldb] r149741 - in /lldb/trunk/test/lang/cpp/dynamic-value: TestCppValueCast.py sbvalue-cast.cpp Message-ID: <20120204020734.A77792A6C12C@llvm.org> Author: johnny Date: Fri Feb 3 20:07:33 2012 New Revision: 149741 URL: http://llvm.org/viewvc/llvm-project?rev=149741&view=rev Log: Add test cases for SBValue.Cast(SBType). The test logic needs more polishing. Added: lldb/trunk/test/lang/cpp/dynamic-value/TestCppValueCast.py lldb/trunk/test/lang/cpp/dynamic-value/sbvalue-cast.cpp Added: lldb/trunk/test/lang/cpp/dynamic-value/TestCppValueCast.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/dynamic-value/TestCppValueCast.py?rev=149741&view=auto ============================================================================== --- lldb/trunk/test/lang/cpp/dynamic-value/TestCppValueCast.py (added) +++ lldb/trunk/test/lang/cpp/dynamic-value/TestCppValueCast.py Fri Feb 3 20:07:33 2012 @@ -0,0 +1,126 @@ +""" +Test lldb Python API SBValue::Cast(SBType) for C++ types. +""" + +import os, time +import re +import unittest2 +import lldb, lldbutil +from lldbtest import * + +class CppValueCastTestCase(TestBase): + + mydir = os.path.join("lang", "cpp", "dynamic-value") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + def test_value_cast_with_dsym(self): + """Test SBValue::Cast(SBType) API for C++ types.""" + self.buildDsym(dictionary=self.d) + self.do_sbvalue_cast(self.exe_name) + + @python_api_test + def test_get_dynamic_vals_with_dwarf(self): + """Test SBValue::Cast(SBType) API for C++ types.""" + self.buildDwarf(dictionary=self.d) + self.do_sbvalue_cast(self.exe_name) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + # Find the line number to break for main.c. + self.source = 'sbvalue-cast.cpp'; + self.line = line_number(self.source, '// Set breakpoint here.') + self.exe_name = self.testMethodName + self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} + + def do_sbvalue_cast (self, exe_name): + """Test SBValue::Cast(SBType) API for C++ types.""" + exe = os.path.join(os.getcwd(), exe_name) + + # Create a target from the debugger. + + target = self.dbg.CreateTarget (exe) + self.assertTrue(target, VALID_TARGET) + + # Set up our breakpoints: + + breakpoint = target.BreakpointCreateByLocation(self.source, self.line) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at the entry point. + process = target.LaunchSimple (None, None, os.getcwd()) + + self.assertTrue(process.GetState() == lldb.eStateStopped, + PROCESS_STOPPED) + + # Find DerivedA and DerivedB types. + typeA = target.FindFirstType('DerivedA') + typeB = target.FindFirstType('DerivedB') + self.DebugSBType(typeA) + self.DebugSBType(typeB) + self.assertTrue(typeA) + self.assertTrue(typeB) + error = lldb.SBError() + + # First stop is for DerivedA instance. + threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) + self.assertTrue (len(threads) == 1) + thread = threads[0] + frame0 = thread.GetFrameAtIndex(0) + + tellerA = frame0.FindVariable('teller', lldb.eNoDynamicValues) + self.DebugSBValue(tellerA) + self.assertTrue(tellerA.GetChildMemberWithName('m_base_val').GetValueAsUnsigned(error, 0) == 20) + + if self.TraceOn(): + for child in tellerA: + print "child name:", child.GetName() + print child + + # Call SBValue.Cast() to obtain instanceA. + instanceA = tellerA.Cast(typeA.GetPointerType()) + self.DebugSBValue(instanceA) + + # These outputs don't look correct? + if self.TraceOn(): + for child in instanceA: + print "child name:", child.GetName() + print child + a_member_val = instanceA.GetChildMemberWithName('m_a_val') + self.DebugSBValue(a_member_val) + + # Second stop is for DerivedB instance. + threads = lldbutil.continue_to_breakpoint (process, breakpoint) + self.assertTrue (len(threads) == 1) + thread = threads[0] + frame0 = thread.GetFrameAtIndex(0) + + tellerB = frame0.FindVariable('teller', lldb.eNoDynamicValues) + self.DebugSBValue(tellerB) + self.assertTrue(tellerB.GetChildMemberWithName('m_base_val').GetValueAsUnsigned(error, 0) == 12) + + if self.TraceOn(): + for child in tellerB: + print "child name:", child.GetName() + print child + + # Call SBValue.Cast() to obtain instanceB. + instanceB = tellerB.Cast(typeB.GetPointerType()) + self.DebugSBValue(instanceB) + + # These outputs don't look correct? + if self.TraceOn(): + for child in instanceB: + print "child name:", child.GetName() + print child + b_member_val = instanceB.GetChildMemberWithName('m_b_val') + self.DebugSBValue(b_member_val) + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/lang/cpp/dynamic-value/sbvalue-cast.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/dynamic-value/sbvalue-cast.cpp?rev=149741&view=auto ============================================================================== --- lldb/trunk/test/lang/cpp/dynamic-value/sbvalue-cast.cpp (added) +++ lldb/trunk/test/lang/cpp/dynamic-value/sbvalue-cast.cpp Fri Feb 3 20:07:33 2012 @@ -0,0 +1,72 @@ +//===-- sbvalue-cast.cpp ----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include + +class Base +{ +public: + Base(int val) : m_base_val (val) {} + virtual ~Base() {} + + virtual void + forcast(int input) { + int future_val = m_base_val + input * 1; + printf("Forcasting %d\n", future_val); + } + +protected: + int m_base_val; +}; + +class DerivedA : public virtual Base +{ +public: + DerivedA(int val) : Base(val*2), m_a_val(val) { + printf("DerivedA::ctor()->\n"); + printf("m_base_val=%d\n", m_base_val); + printf("m_a_val=%d\n", m_a_val); + } + virtual ~DerivedA() {} + +private: + int m_a_val; +}; + +class DerivedB : public virtual Base +{ +public: + DerivedB(int val) : Base(val), m_b_val(val*3) { + printf("DerivedB::ctor()->\n"); + printf("m_base_val=%d\n", m_base_val); + printf("m_b_val=%d\n", m_b_val); + } + virtual ~DerivedB() {} + + virtual void + forcast(int input) { + int future_val = m_b_val + input * 2; + printf("Forcasting %d\n", future_val); + } + +private: + int m_b_val; +}; + +int +main(int argc, char **argv) +{ + Base *array[2] = {new DerivedA(10), new DerivedB(12)}; + Base *teller = NULL; + for (int i = 0; i < 2; ++i) { + teller = array[i]; + teller->forcast(i); // Set breakpoint here. + } + + return 0; +} From gclayton at apple.com Fri Feb 3 20:27:34 2012 From: gclayton at apple.com (Greg Clayton) Date: Sat, 04 Feb 2012 02:27:34 -0000 Subject: [Lldb-commits] [lldb] r149743 - in /lldb/trunk: include/lldb/API/ include/lldb/Core/ include/lldb/Symbol/ scripts/Python/ source/API/ source/Core/ source/Symbol/ test/ test/expression_command/test/ test/lang/c/array_types/ test/lang/cpp/class_types/ test/lang/cpp/stl/ test/python_api/module_section/ test/python_api/sbdata/ test/python_api/symbol-context/ Message-ID: <20120204022735.9D4F62A6C12C@llvm.org> Author: gclayton Date: Fri Feb 3 20:27:34 2012 New Revision: 149743 URL: http://llvm.org/viewvc/llvm-project?rev=149743&view=rev Log: Convert all python objects in our API to use overload the __str__ method instead of the __repr__. __repr__ is a function that should return an expression that can be used to recreate an python object and we were using it to just return a human readable string. Fixed a crasher when using the new implementation of SBValue::Cast(SBType). Thread hardened lldb::SBValue and lldb::SBWatchpoint and did other general improvements to the API. Fixed a crasher in lldb::SBValue::GetChildMemberWithName() where we didn't correctly handle not having a target. Modified: lldb/trunk/include/lldb/API/SBType.h lldb/trunk/include/lldb/API/SBValue.h lldb/trunk/include/lldb/API/SBWatchpoint.h lldb/trunk/include/lldb/Core/ValueObject.h lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h lldb/trunk/include/lldb/Core/ValueObjectVariable.h lldb/trunk/include/lldb/Symbol/ClangASTType.h lldb/trunk/scripts/Python/python-extensions.swig lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/API/SBTarget.cpp lldb/trunk/source/API/SBType.cpp lldb/trunk/source/API/SBValue.cpp lldb/trunk/source/API/SBValueList.cpp lldb/trunk/source/API/SBWatchpoint.cpp lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/source/Core/ValueObjectDynamicValue.cpp lldb/trunk/source/Core/ValueObjectVariable.cpp lldb/trunk/source/Symbol/ClangASTType.cpp lldb/trunk/test/expression_command/test/TestExprs.py lldb/trunk/test/lang/c/array_types/TestArrayTypes.py lldb/trunk/test/lang/cpp/class_types/TestClassTypes.py lldb/trunk/test/lang/cpp/stl/TestStdCXXDisassembly.py lldb/trunk/test/lldbutil.py lldb/trunk/test/python_api/module_section/TestModuleAndSection.py lldb/trunk/test/python_api/sbdata/TestSBData.py lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py Modified: lldb/trunk/include/lldb/API/SBType.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBType.h (original) +++ lldb/trunk/include/lldb/API/SBType.h Fri Feb 3 20:27:34 2012 @@ -167,6 +167,9 @@ const lldb_private::TypeImpl & ref () const; + lldb::TypeImplSP + GetSP (); + void SetSP (const lldb::TypeImplSP &type_impl_sp); #endif Modified: lldb/trunk/include/lldb/API/SBValue.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBValue.h (original) +++ lldb/trunk/include/lldb/API/SBValue.h Fri Feb 3 20:27:34 2012 @@ -355,27 +355,13 @@ friend class SBValueList; friend class SBFrame; -#ifndef SWIG - // Mimic shared pointer... - lldb_private::ValueObject * - get() const; - - lldb_private::ValueObject * - operator->() const; - - lldb::ValueObjectSP & - operator*(); - - const lldb::ValueObjectSP & - operator*() const; - -#endif - + lldb::ValueObjectSP + GetSP () const; + + void + SetSP (const lldb::ValueObjectSP &sp); + private: - // Helper function for SBValue::Watch() and SBValue::WatchPointee(). - lldb::SBWatchpoint - WatchValue(bool read, bool write, bool watch_pointee); - lldb::ValueObjectSP m_opaque_sp; }; Modified: lldb/trunk/include/lldb/API/SBWatchpoint.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBWatchpoint.h?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBWatchpoint.h (original) +++ lldb/trunk/include/lldb/API/SBWatchpoint.h Fri Feb 3 20:27:34 2012 @@ -22,12 +22,12 @@ SBWatchpoint (const lldb::SBWatchpoint &rhs); + SBWatchpoint (const lldb::WatchpointSP &wp_sp); + ~SBWatchpoint (); -#ifndef SWIG const lldb::SBWatchpoint & operator = (const lldb::SBWatchpoint &rhs); -#endif bool IsValid() const; @@ -72,27 +72,20 @@ bool GetDescription (lldb::SBStream &description, DescriptionLevel level); -#ifndef SWIG - SBWatchpoint (const lldb::WatchpointSP &wp_sp); -#endif + void + Clear (); + + lldb::WatchpointSP + GetSP () const; + + void + SetSP (const lldb::WatchpointSP &sp); private: friend class SBTarget; friend class SBValue; -#ifndef SWIG - - lldb_private::Watchpoint * - operator->(); - - lldb_private::Watchpoint * - get(); - - lldb::WatchpointSP & - operator *(); - -#endif - + lldb::WatchpointSP m_opaque_sp; }; Modified: lldb/trunk/include/lldb/Core/ValueObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObject.h (original) +++ lldb/trunk/include/lldb/Core/ValueObject.h Fri Feb 3 20:27:34 2012 @@ -518,6 +518,9 @@ virtual ConstString GetTypeName() = 0; + //------------------------------------------------------------------ + // Sublasses can implement the functions below. + //------------------------------------------------------------------ virtual lldb::LanguageType GetObjectRuntimeLanguage(); @@ -632,6 +635,10 @@ return m_parent->GetModule(); return NULL; } + + virtual bool + GetDeclaration (Declaration &decl); + //------------------------------------------------------------------ // The functions below should NOT be modified by sublasses //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectDynamicValue.h Fri Feb 3 20:27:34 2012 @@ -22,6 +22,11 @@ class ValueObjectCast : public ValueObject { public: + static lldb::ValueObjectSP + Create (ValueObject &parent, + const ConstString &name, + const ClangASTType &cast_type); + virtual ~ValueObjectCast(); @@ -83,7 +88,6 @@ ClangASTType m_cast_type; private: - friend class ValueObject; ValueObjectCast (ValueObject &parent, const ConstString &name, const ClangASTType &cast_type); Modified: lldb/trunk/include/lldb/Core/ValueObjectVariable.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectVariable.h?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectVariable.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectVariable.h Fri Feb 3 20:27:34 2012 @@ -58,6 +58,9 @@ virtual SymbolContextScope * GetSymbolContextScope(); + virtual bool + GetDeclaration (Declaration &decl); + protected: virtual bool UpdateValue (); Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Fri Feb 3 20:27:34 2012 @@ -301,7 +301,7 @@ uint32_t& stride); lldb::clang_type_t - GetPointerType (); + GetPointerType () const; static lldb::clang_type_t GetPointerType (clang::ASTContext *ast_context, Modified: lldb/trunk/scripts/Python/python-extensions.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-extensions.swig (original) +++ lldb/trunk/scripts/Python/python-extensions.swig Fri Feb 3 20:27:34 2012 @@ -1,6 +1,6 @@ %extend lldb::SBAddress { - PyObject *lldb::SBAddress::__repr__ (){ + PyObject *lldb::SBAddress::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -9,11 +9,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBBlock { - PyObject *lldb::SBBlock::__repr__ (){ + PyObject *lldb::SBBlock::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -22,11 +23,13 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); + } } %extend lldb::SBBreakpoint { - PyObject *lldb::SBBreakpoint::__repr__ (){ + PyObject *lldb::SBBreakpoint::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -35,11 +38,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBBreakpointLocation { - PyObject *lldb::SBBreakpointLocation::__repr__ (){ + PyObject *lldb::SBBreakpointLocation::__str__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelFull); const char *desc = description.GetData(); @@ -48,11 +52,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBCommandReturnObject { - PyObject *lldb::SBCommandReturnObject::__repr__ (){ + PyObject *lldb::SBCommandReturnObject::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -61,11 +66,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBCompileUnit { - PyObject *lldb::SBCompileUnit::__repr__ (){ + PyObject *lldb::SBCompileUnit::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -74,11 +80,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBData { - PyObject *lldb::SBData::__repr__ (){ + PyObject *lldb::SBData::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -87,11 +94,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBDebugger { - PyObject *lldb::SBDebugger::__repr__ (){ + PyObject *lldb::SBDebugger::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -100,11 +108,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBError { - PyObject *lldb::SBError::__repr__ (){ + PyObject *lldb::SBError::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -113,11 +122,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBFileSpec { - PyObject *lldb::SBFileSpec::__repr__ (){ + PyObject *lldb::SBFileSpec::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -126,11 +136,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBFrame { - PyObject *lldb::SBFrame::__repr__ (){ + PyObject *lldb::SBFrame::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -139,11 +150,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBFunction { - PyObject *lldb::SBFunction::__repr__ (){ + PyObject *lldb::SBFunction::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -152,11 +164,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBInstruction { - PyObject *lldb::SBInstruction::__repr__ (){ + PyObject *lldb::SBInstruction::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -165,11 +178,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBInstructionList { - PyObject *lldb::SBInstructionList::__repr__ (){ + PyObject *lldb::SBInstructionList::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -178,11 +192,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBLineEntry { - PyObject *lldb::SBLineEntry::__repr__ (){ + PyObject *lldb::SBLineEntry::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -191,11 +206,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBModule { - PyObject *lldb::SBModule::__repr__ (){ + PyObject *lldb::SBModule::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -204,11 +220,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBProcess { - PyObject *lldb::SBProcess::__repr__ (){ + PyObject *lldb::SBProcess::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -217,11 +234,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBSection { - PyObject *lldb::SBSection::__repr__ (){ + PyObject *lldb::SBSection::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -230,11 +248,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBSymbol { - PyObject *lldb::SBSymbol::__repr__ (){ + PyObject *lldb::SBSymbol::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -243,11 +262,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBSymbolContext { - PyObject *lldb::SBSymbolContext::__repr__ (){ + PyObject *lldb::SBSymbolContext::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -256,11 +276,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBTarget { - PyObject *lldb::SBTarget::__repr__ (){ + PyObject *lldb::SBTarget::__str__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelBrief); const char *desc = description.GetData(); @@ -269,11 +290,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBType { - PyObject *lldb::SBType::__repr__ (){ + PyObject *lldb::SBType::__str__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelBrief); const char *desc = description.GetData(); @@ -282,11 +304,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBTypeMember { - PyObject *lldb::SBTypeMember::__repr__ (){ + PyObject *lldb::SBTypeMember::__str__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelBrief); const char *desc = description.GetData(); @@ -295,11 +318,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBThread { - PyObject *lldb::SBThread::__repr__ (){ + PyObject *lldb::SBThread::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -308,11 +332,12 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBValue { - PyObject *lldb::SBValue::__repr__ (){ + PyObject *lldb::SBValue::__str__ (){ lldb::SBStream description; $self->GetDescription (description); const char *desc = description.GetData(); @@ -321,7 +346,8 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } %extend lldb::SBValueList { @@ -347,7 +373,7 @@ } } %extend lldb::SBWatchpoint { - PyObject *lldb::SBWatchpoint::__repr__ (){ + PyObject *lldb::SBWatchpoint::__str__ (){ lldb::SBStream description; $self->GetDescription (description, lldb::eDescriptionLevelVerbose); const char *desc = description.GetData(); @@ -356,7 +382,8 @@ --desc_len; if (desc_len > 0) return PyString_FromStringAndSize (desc, desc_len); - return Py_None; + else + return PyString_FromString(""); } } @@ -382,9 +409,6 @@ def __nonzero__(self): return self.sbvalue.__nonzero__() - def __repr__(self): - return self.sbvalue.__repr__() - def __str__(self): return self.sbvalue.__str__() Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Fri Feb 3 20:27:34 2012 @@ -483,7 +483,7 @@ StackFrame::eExpressionPathOptionCheckPtrVsMember, var_sp, error)); - *sb_value = value_sp; + sb_value.SetSP(value_sp); } return sb_value; } @@ -507,6 +507,7 @@ { VariableSP var_sp; SBValue sb_value; + ValueObjectSP value_sp; StackFrameSP frame_sp(GetFrameSP()); if (frame_sp && name && name[0]) { @@ -530,14 +531,17 @@ } if (var_sp) - *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic)); + { + value_sp = frame_sp->GetValueObjectForFrameVariable(var_sp, use_dynamic); + sb_value.SetSP(value_sp); + } } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", - frame_sp.get(), name, sb_value.get()); + frame_sp.get(), name, value_sp.get()); return sb_value; } @@ -559,6 +563,7 @@ SBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) { SBValue sb_value; + ValueObjectSP value_sp; StackFrameSP frame_sp(GetFrameSP()); if (frame_sp && name && name[0]) { @@ -593,8 +598,8 @@ variable_sp->GetScope() == value_type && variable_sp->GetName() == const_name) { - *sb_value = ValueObjectSP (frame_sp->GetValueObjectForFrameVariable(variable_sp, - use_dynamic)); + value_sp = frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic); + sb_value.SetSP (value_sp); break; } } @@ -615,7 +620,9 @@ ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) { - *sb_value = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx); + value_sp = ValueObjectRegister::Create (frame_sp.get(), reg_ctx, reg_idx); + sb_value.SetSP (value_sp); + break; } } } @@ -635,7 +642,9 @@ ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) { - *sb_value = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx); + value_sp = ValueObjectRegisterSet::Create (frame_sp.get(), reg_ctx, set_idx); + sb_value.SetSP (value_sp); + break; } } } @@ -647,7 +656,10 @@ ConstString const_name(name); ClangExpressionVariableSP expr_var_sp (frame_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name)); if (expr_var_sp) - *sb_value = expr_var_sp->GetValueObject(); + { + value_sp = expr_var_sp->GetValueObject(); + sb_value.SetSP (value_sp); + } } break; @@ -659,7 +671,7 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", - frame_sp.get(), name, value_type, sb_value.get()); + frame_sp.get(), name, value_type, value_sp.get()); return sb_value; @@ -885,6 +897,7 @@ ExecutionResults exe_results; SBValue expr_result; + ValueObjectSP expr_value_sp; StackFrameSP frame_sp(GetFrameSP()); if (log) @@ -912,8 +925,8 @@ unwind_on_error, keep_in_memory, fetch_dynamic_value, - *expr_result); - + expr_value_sp); + expr_result.SetSP(expr_value_sp); Host::SetCrashDescription (NULL); } @@ -925,7 +938,7 @@ if (log) log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", frame_sp.get(), expr, - expr_result.get(), + expr_value_sp.get(), exe_results); return expr_result; Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Fri Feb 3 20:27:34 2012 @@ -947,7 +947,7 @@ if (target_sp) { // The watchpoint list is thread safe, no need to lock - *sb_watchpoint = target_sp->GetWatchpointList().GetByIndex(idx); + sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx)); } return sb_watchpoint; } @@ -979,17 +979,19 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBWatchpoint sb_watchpoint; + lldb::WatchpointSP watchpoint_sp; TargetSP target_sp(GetSP()); if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) { Mutex::Locker api_locker (target_sp->GetAPIMutex()); - *sb_watchpoint = target_sp->GetWatchpointList().FindByID(wp_id); + watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); + sb_watchpoint.SetSP (watchpoint_sp); } if (log) { log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", - target_sp.get(), (uint32_t) wp_id, sb_watchpoint.get()); + target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get()); } return sb_watchpoint; @@ -1001,19 +1003,24 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBWatchpoint sb_watchpoint; + lldb::WatchpointSP watchpoint_sp; TargetSP target_sp(GetSP()); - if (target_sp) + if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0) { Mutex::Locker api_locker (target_sp->GetAPIMutex()); - uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) | - (write ? LLDB_WATCH_TYPE_WRITE : 0); - sb_watchpoint = target_sp->CreateWatchpoint(addr, size, watch_type); + uint32_t watch_type = 0; + if (read) + watch_type |= LLDB_WATCH_TYPE_READ; + if (write) + watch_type |= LLDB_WATCH_TYPE_WRITE; + watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type); + sb_watchpoint.SetSP (watchpoint_sp); } if (log) { log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)", - target_sp.get(), addr, (uint32_t) size, sb_watchpoint.get()); + target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get()); } return sb_watchpoint; Modified: lldb/trunk/source/API/SBType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/API/SBType.cpp (original) +++ lldb/trunk/source/API/SBType.cpp Fri Feb 3 20:27:34 2012 @@ -83,6 +83,13 @@ (rhs.m_opaque_sp->GetOpaqueQualType() != m_opaque_sp->GetOpaqueQualType()); } +lldb::TypeImplSP +SBType::GetSP () +{ + return m_opaque_sp; +} + + void SBType::SetSP (const lldb::TypeImplSP &type_impl_sp) { Modified: lldb/trunk/source/API/SBValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/API/SBValue.cpp (original) +++ lldb/trunk/source/API/SBValue.cpp Fri Feb 3 20:27:34 2012 @@ -22,6 +22,7 @@ #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Symbol/Block.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Symbol/Type.h" #include "lldb/Symbol/Variable.h" #include "lldb/Symbol/VariableList.h" #include "lldb/Target/ExecutionContext.h" @@ -86,8 +87,9 @@ { SBError sb_error; - if (m_opaque_sp.get()) - sb_error.SetError(m_opaque_sp->GetError()); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + sb_error.SetError(value_sp->GetError()); else sb_error.SetErrorString("error: invalid value"); @@ -97,8 +99,9 @@ user_id_t SBValue::GetID() { - if (m_opaque_sp) - return m_opaque_sp->GetID(); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + return value_sp->GetID(); return LLDB_INVALID_UID; } @@ -107,16 +110,17 @@ { const char *name = NULL; - if (m_opaque_sp) - name = m_opaque_sp->GetName().GetCString(); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + name = value_sp->GetName().GetCString(); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (name) - log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name); + log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name); else - log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get()); } return name; @@ -126,15 +130,16 @@ SBValue::GetTypeName () { const char *name = NULL; - if (m_opaque_sp) - name = m_opaque_sp->GetTypeName().GetCString(); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + name = value_sp->GetTypeName().GetCString(); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (name) - log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name); + log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name); else - log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get()); } return name; @@ -145,12 +150,13 @@ { size_t result = 0; - if (m_opaque_sp) - result = m_opaque_sp->GetByteSize(); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + result = value_sp->GetByteSize(); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result); + log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result); return result; } @@ -160,18 +166,20 @@ { bool result = false; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - result = m_opaque_sp->IsInScope (); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + result = value_sp->IsInScope (); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result); + log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result); return result; } @@ -180,21 +188,23 @@ SBValue::GetValue () { const char *cstr = NULL; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - cstr = m_opaque_sp->GetValueAsCString (); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + cstr = value_sp->GetValueAsCString (); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr); + log->Printf ("SBValue(%p)::GetValue => \"%s\"", value_sp.get(), cstr); else - log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetValue => NULL", value_sp.get()); } return cstr; @@ -204,22 +214,23 @@ SBValue::GetValueType () { ValueType result = eValueTypeInvalid; - if (m_opaque_sp) - result = m_opaque_sp->GetValueType(); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + result = value_sp->GetValueType(); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { switch (result) { - case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break; - case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break; - case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break; - case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break; - case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break; - case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break; - case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break; - case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break; - default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break; + case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break; + case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break; + case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break; + case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break; + case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break; + case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break; + case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break; + case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break; + default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break; } } return result; @@ -229,21 +240,23 @@ SBValue::GetObjectDescription () { const char *cstr = NULL; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - cstr = m_opaque_sp->GetObjectDescription (); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + cstr = value_sp->GetObjectDescription (); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr); + log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", value_sp.get(), cstr); else - log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetObjectDescription => NULL", value_sp.get()); } return cstr; } @@ -251,41 +264,42 @@ SBType SBValue::GetType() { - SBType result; - if (m_opaque_sp) + SBType sb_type; + lldb::ValueObjectSP value_sp(GetSP()); + TypeImplSP type_sp; + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) - { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType())); - } + type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType()))); + sb_type.SetSP(type_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.IsValid()) - log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result); + if (type_sp) + log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get()); else - log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get()); } - return result; + return sb_type; } bool SBValue::GetValueDidChange () { bool result = false; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - result = m_opaque_sp->GetValueDidChange (); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + result = value_sp->GetValueDidChange (); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result); + log->Printf ("SBValue(%p)::GetValueDidChange => %i", value_sp.get(), result); return result; } @@ -294,21 +308,23 @@ SBValue::GetSummary () { const char *cstr = NULL; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - cstr = m_opaque_sp->GetSummaryAsCString(); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + cstr = value_sp->GetSummaryAsCString(); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr); + log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr); else - log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get()); } return cstr; } @@ -317,21 +333,23 @@ SBValue::GetLocation () { const char *cstr = NULL; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - cstr = m_opaque_sp->GetLocationAsCString(); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + cstr = value_sp->GetLocationAsCString(); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr); + log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr); else - log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get()); } return cstr; } @@ -340,12 +358,14 @@ SBValue::SetValueFromCString (const char *value_str) { bool success = false; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - success = m_opaque_sp->SetValueFromCString (value_str); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + success = value_sp->SetValueFromCString (value_str); } } return success; @@ -354,136 +374,147 @@ lldb::SBValue SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type) { - lldb::SBValue result; - if (m_opaque_sp) + lldb::SBValue sb_value; + lldb::ValueObjectSP value_sp(GetSP()); + lldb::ValueObjectSP new_value_sp; + if (value_sp) { + TypeImplSP type_sp (type.GetSP()); if (type.IsValid()) { - result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true)); - result.m_opaque_sp->SetName(ConstString(name)); + sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true)); + new_value_sp = sb_value.GetSP(); + if (new_value_sp) + new_value_sp->SetName(ConstString(name)); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.IsValid()) - log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); + if (new_value_sp) + log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); else - log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get()); } - return result; + return sb_value; } lldb::SBValue SBValue::Cast (SBType type) { lldb::SBValue sb_value; - if (m_opaque_sp && type.IsValid()) - *sb_value = m_opaque_sp->Cast(type.ref().GetClangASTType()); + lldb::ValueObjectSP value_sp(GetSP()); + TypeImplSP type_sp (type.GetSP()); + if (value_sp && type_sp) + sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType())); return sb_value; } lldb::SBValue SBValue::CreateValueFromExpression (const char *name, const char* expression) { - lldb::SBValue result; - if (m_opaque_sp) + lldb::SBValue sb_value; + lldb::ValueObjectSP value_sp(GetSP()); + lldb::ValueObjectSP new_value_sp; + if (value_sp) { - ValueObjectSP result_valobj_sp; - m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression, - m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame(), - eExecutionPolicyOnlyWhenNeeded, - false, // coerce to id - true, // unwind on error - true, // keep in memory - eNoDynamicValues, - result_valobj_sp); - if (result_valobj_sp) + value_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression, + value_sp->GetExecutionContextScope()->CalculateStackFrame(), + eExecutionPolicyOnlyWhenNeeded, + false, // coerce to id + true, // unwind on error + true, // keep in memory + eNoDynamicValues, + new_value_sp); + if (new_value_sp) { - result_valobj_sp->SetName(ConstString(name)); - result = SBValue(result_valobj_sp); + new_value_sp->SetName(ConstString(name)); + sb_value.SetSP(new_value_sp); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.IsValid()) - log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); + if (new_value_sp) + log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); else - log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get()); } - return result; + return sb_value; } lldb::SBValue -SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type) +SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type) { - lldb::SBValue result; - if (m_opaque_sp && type.IsValid() && type.GetPointerType().IsValid()) - { - SBType real_type(type.GetPointerType()); - - lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); + lldb::SBValue sb_value; + lldb::ValueObjectSP value_sp(GetSP()); + lldb::ValueObjectSP new_value_sp; + lldb::TypeImplSP type_impl_sp (sb_type.GetSP()); + if (value_sp && type_impl_sp) + { + ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ()); + lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type)); + if (pointee_type_impl_sp) + { - ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(), - real_type.m_opaque_sp->GetASTContext(), - real_type.m_opaque_sp->GetOpaqueQualType(), - ConstString(name), - buffer, - lldb::endian::InlHostByteOrder(), - GetTarget().GetProcess().GetAddressByteSize())); + lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); - ValueObjectSP result_valobj_sp; + ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (value_sp->GetExecutionContextScope(), + pointee_type_impl_sp->GetASTContext(), + pointee_type_impl_sp->GetOpaqueQualType(), + ConstString(name), + buffer, + lldb::endian::InlHostByteOrder(), + GetTarget().GetProcess().GetAddressByteSize())); - ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); - if (ptr_result_valobj_sp) - { - Error err; - result_valobj_sp = ptr_result_valobj_sp->Dereference(err); - if (result_valobj_sp) - result_valobj_sp->SetName(ConstString(name)); + if (ptr_result_valobj_sp) + { + ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); + Error err; + new_value_sp = ptr_result_valobj_sp->Dereference(err); + if (new_value_sp) + new_value_sp->SetName(ConstString(name)); + } + sb_value.SetSP(new_value_sp); } - result = SBValue(result_valobj_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.IsValid()) - log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); + if (new_value_sp) + log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); else - log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get()); } - return result; + return sb_value; } lldb::SBValue SBValue::CreateValueFromData (const char* name, SBData data, SBType type) { - SBValue result; - - AddressType addr_of_children_priv = eAddressTypeLoad; - - if (m_opaque_sp) + lldb::SBValue sb_value; + lldb::ValueObjectSP new_value_sp; + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - ValueObjectSP valobj_sp; - valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(), - type.m_opaque_sp->GetASTContext() , - type.m_opaque_sp->GetOpaqueQualType(), - ConstString(name), - *data.m_opaque_sp, - LLDB_INVALID_ADDRESS); - valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv); - result = SBValue(valobj_sp); + new_value_sp = ValueObjectConstResult::Create (value_sp->GetExecutionContextScope(), + type.m_opaque_sp->GetASTContext() , + type.m_opaque_sp->GetOpaqueQualType(), + ConstString(name), + *data.m_opaque_sp, + LLDB_INVALID_ADDRESS); + new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); + sb_value.SetSP(new_value_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - if (result.IsValid()) - log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString()); + if (new_value_sp) + log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); else - log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get()); } - return result; + return sb_value; } SBValue @@ -491,8 +522,9 @@ { const bool can_create_synthetic = false; lldb::DynamicValueType use_dynamic = eNoDynamicValues; - if (m_opaque_sp) - use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue(); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + use_dynamic = value_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue(); return GetChildAtIndex (idx, use_dynamic, can_create_synthetic); } @@ -501,22 +533,24 @@ { lldb::ValueObjectSP child_sp; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); const bool can_create = true; - child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create); + child_sp = value_sp->GetChildAtIndex (idx, can_create); if (can_create_synthetic && !child_sp) { - if (m_opaque_sp->IsPointerType()) + if (value_sp->IsPointerType()) { - child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create); + child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create); } - else if (m_opaque_sp->IsArrayType()) + else if (value_sp->IsArrayType()) { - child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create); + child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create); } } @@ -535,7 +569,7 @@ SBValue sb_value (child_sp); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get()); + log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get()); return sb_value; } @@ -544,22 +578,24 @@ SBValue::GetIndexOfChildWithName (const char *name) { uint32_t idx = UINT32_MAX; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name)); + idx = value_sp->GetIndexOfChildWithName (ConstString(name)); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (idx == UINT32_MAX) - log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name); + log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name); else - log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx); + log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx); } return idx; } @@ -567,13 +603,19 @@ SBValue SBValue::GetChildMemberWithName (const char *name) { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue(); + lldb::DynamicValueType use_dynamic_value = eNoDynamicValues; + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) + { + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + use_dynamic_value = target_sp->GetPreferDynamicValue(); + } return GetChildMemberWithName (name, use_dynamic_value); } - else - return GetChildMemberWithName (name, eNoDynamicValues); + return SBValue(); } SBValue @@ -583,12 +625,14 @@ const ConstString str_name (name); - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true); + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + child_sp = value_sp->GetChildMemberWithName (str_name, true); if (use_dynamic_value != lldb::eNoDynamicValues) { if (child_sp) @@ -605,7 +649,7 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get()); + log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get()); return sb_value; } @@ -613,12 +657,14 @@ lldb::SBValue SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic) { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - return SBValue (m_opaque_sp->GetDynamicValue(use_dynamic)); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + return SBValue (value_sp->GetDynamicValue(use_dynamic)); } } @@ -628,12 +674,14 @@ lldb::SBValue SBValue::GetStaticValue () { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - return SBValue(m_opaque_sp->GetStaticValue()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + return SBValue(value_sp->GetStaticValue()); } } @@ -643,12 +691,14 @@ bool SBValue::IsDynamic() { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - return m_opaque_sp->IsDynamic(); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + return value_sp->IsDynamic(); } } return false; @@ -658,13 +708,15 @@ SBValue::GetValueForExpressionPath(const char* expr_path) { lldb::ValueObjectSP child_sp; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); // using default values for all the fancy options, just do it if you can - child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path); + child_sp = value_sp->GetValueForExpressionPath(expr_path); } } @@ -672,7 +724,7 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get()); + log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get()); return sb_value; } @@ -681,13 +733,15 @@ SBValue::GetValueAsSigned(SBError& error, int64_t fail_value) { error.Clear(); - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); Scalar scalar; - if (m_opaque_sp->ResolveValue (scalar)) + if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); else error.SetErrorString("could not get value"); @@ -703,13 +757,15 @@ SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) { error.Clear(); - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); Scalar scalar; - if (m_opaque_sp->ResolveValue (scalar)) + if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); else error.SetErrorString("could not get value"); @@ -724,13 +780,15 @@ int64_t SBValue::GetValueAsSigned(int64_t fail_value) { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); Scalar scalar; - if (m_opaque_sp->ResolveValue (scalar)) + if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); } } @@ -740,13 +798,15 @@ uint64_t SBValue::GetValueAsUnsigned(uint64_t fail_value) { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); Scalar scalar; - if (m_opaque_sp->ResolveValue (scalar)) + if (value_sp->ResolveValue (scalar)) return scalar.GetRawBits64(fail_value); } } @@ -758,19 +818,21 @@ { uint32_t num_children = 0; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - num_children = m_opaque_sp->GetNumChildren(); + num_children = value_sp->GetNumChildren(); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children); + log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children); return num_children; } @@ -780,19 +842,21 @@ SBValue::Dereference () { SBValue sb_value; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); Error error; - sb_value = m_opaque_sp->Dereference (error); + sb_value = value_sp->Dereference (error); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get()); + log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get()); return sb_value; } @@ -802,19 +866,21 @@ { bool is_ptr_type = false; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - is_ptr_type = m_opaque_sp->IsPointerType(); + is_ptr_type = value_sp->IsPointerType(); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type); + log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type); return is_ptr_type; @@ -823,13 +889,15 @@ void * SBValue::GetOpaqueType() { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetUpdatePoint().GetTargetSP()) + TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); + Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex()); - return m_opaque_sp->GetClangType(); + return value_sp->GetClangType(); } } return NULL; @@ -840,18 +908,19 @@ { SBTarget sb_target; TargetSP target_sp; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - target_sp = m_opaque_sp->GetUpdatePoint().GetTargetSP(); + target_sp = value_sp->GetUpdatePoint().GetTargetSP(); sb_target.SetSP (target_sp); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (target_sp.get() == NULL) - log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get()); else - log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get()); + log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get()); } return sb_target; } @@ -861,9 +930,10 @@ { SBProcess sb_process; ProcessSP process_sp; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - process_sp = m_opaque_sp->GetUpdatePoint().GetProcessSP(); + process_sp = value_sp->GetUpdatePoint().GetProcessSP(); if (process_sp) sb_process.SetSP (process_sp); } @@ -871,9 +941,9 @@ if (log) { if (process_sp.get() == NULL) - log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get()); else - log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get()); + log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get()); } return sb_process; } @@ -883,11 +953,12 @@ { SBThread sb_thread; ThreadSP thread_sp; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetExecutionContextScope()) + if (value_sp->GetExecutionContextScope()) { - thread_sp = m_opaque_sp->GetExecutionContextScope()->CalculateThread()->shared_from_this(); + thread_sp = value_sp->GetExecutionContextScope()->CalculateThread()->shared_from_this(); sb_thread.SetThread(thread_sp); } } @@ -895,9 +966,9 @@ if (log) { if (thread_sp.get() == NULL) - log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get()); else - log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get()); + log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get()); } return sb_thread; } @@ -907,11 +978,12 @@ { SBFrame sb_frame; StackFrameSP frame_sp; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - if (m_opaque_sp->GetExecutionContextScope()) + if (value_sp->GetExecutionContextScope()) { - frame_sp = m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this(); + frame_sp = value_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this(); sb_frame.SetFrameSP (frame_sp); } } @@ -919,45 +991,34 @@ if (log) { if (frame_sp.get() == NULL) - log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get()); + log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get()); else - log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get()); + log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get()); } return sb_frame; } -// Mimic shared pointer... -lldb_private::ValueObject * -SBValue::get() const -{ - return m_opaque_sp.get(); -} - -lldb_private::ValueObject * -SBValue::operator->() const -{ - return m_opaque_sp.get(); -} - -lldb::ValueObjectSP & -SBValue::operator*() +lldb::ValueObjectSP +SBValue::GetSP () const { return m_opaque_sp; } -const lldb::ValueObjectSP & -SBValue::operator*() const +void +SBValue::SetSP (const lldb::ValueObjectSP &sp) { - return m_opaque_sp; + m_opaque_sp = sp; } + bool SBValue::GetExpressionPath (SBStream &description) { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - m_opaque_sp->GetExpressionPath (description.ref(), false); + value_sp->GetExpressionPath (description.ref(), false); return true; } return false; @@ -966,9 +1027,10 @@ bool SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes) { - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); + value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); return true; } return false; @@ -979,9 +1041,10 @@ { Stream &strm = description.ref(); - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - ValueObject::DumpValueObject (strm, m_opaque_sp.get()); + ValueObject::DumpValueObject (strm, value_sp.get()); } else strm.PutCString ("No value"); @@ -992,35 +1055,38 @@ lldb::Format SBValue::GetFormat () { - if (m_opaque_sp) - return m_opaque_sp->GetFormat(); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + return value_sp->GetFormat(); return eFormatDefault; } void SBValue::SetFormat (lldb::Format format) { - if (m_opaque_sp) - m_opaque_sp->SetFormat(format); + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) + value_sp->SetFormat(format); } lldb::SBValue SBValue::AddressOf() { SBValue sb_value; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); + Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); if (target) { Mutex::Locker api_locker (target->GetAPIMutex()); Error error; - sb_value = m_opaque_sp->AddressOf (error); + sb_value = value_sp->AddressOf (error); } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get()); + log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get()); return sb_value; } @@ -1029,25 +1095,26 @@ SBValue::GetLoadAddress() { lldb::addr_t value = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); + Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); if (target) { Mutex::Locker api_locker (target->GetAPIMutex()); const bool scalar_is_load_address = true; AddressType addr_type; - value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type); + value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); if (addr_type == eAddressTypeFile) { - Module* module = m_opaque_sp->GetModule(); + Module* module = value_sp->GetModule(); if (!module) value = LLDB_INVALID_ADDRESS; else { Address addr; module->ResolveFileAddress(value, addr); - value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get()); + value = addr.GetLoadAddress(value_sp->GetUpdatePoint().GetTargetSP().get()); } } else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid) @@ -1056,7 +1123,7 @@ } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value); + log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value); return value; } @@ -1065,19 +1132,20 @@ SBValue::GetAddress() { Address addr; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); + Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); if (target) { lldb::addr_t value = LLDB_INVALID_ADDRESS; Mutex::Locker api_locker (target->GetAPIMutex()); const bool scalar_is_load_address = true; AddressType addr_type; - value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type); + value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); if (addr_type == eAddressTypeFile) { - Module* module = m_opaque_sp->GetModule(); + Module* module = value_sp->GetModule(); if (module) module->ResolveFileAddress(value, addr); } @@ -1092,7 +1160,7 @@ } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset()); + log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", value_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset()); return SBAddress(new Address(addr)); } @@ -1101,14 +1169,15 @@ uint32_t item_count) { lldb::SBData sb_data; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); + Target* target = value_sp->GetUpdatePoint().GetTargetSP().get(); if (target) { DataExtractorSP data_sp(new DataExtractor()); Mutex::Locker api_locker (target->GetAPIMutex()); - m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count); + value_sp->GetPointeeData(*data_sp, item_idx, item_count); if (data_sp->GetByteSize() > 0) *sb_data = data_sp; } @@ -1116,7 +1185,7 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)", - m_opaque_sp.get(), + value_sp.get(), item_idx, item_count, sb_data.get()); @@ -1128,14 +1197,15 @@ SBValue::GetData () { lldb::SBData sb_data; - if (m_opaque_sp) + lldb::ValueObjectSP value_sp(GetSP()); + if (value_sp) { - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + TargetSP target_sp (value_sp->GetUpdatePoint().GetTargetSP()); + if (target_sp) { + Mutex::Locker api_locker (target_sp->GetAPIMutex()); DataExtractorSP data_sp(new DataExtractor()); - Mutex::Locker api_locker (target->GetAPIMutex()); - m_opaque_sp->GetData(*data_sp); + value_sp->GetData(*data_sp); if (data_sp->GetByteSize() > 0) *sb_data = data_sp; } @@ -1143,7 +1213,7 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBValue(%p)::GetData () => SBData(%p)", - m_opaque_sp.get(), + value_sp.get(), sb_data.get()); return sb_data; @@ -1152,98 +1222,61 @@ lldb::SBWatchpoint SBValue::Watch (bool resolve_location, bool read, bool write) { - lldb::SBWatchpoint sb_watchpoint; - if (!m_opaque_sp) - return sb_watchpoint; - - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) + SBWatchpoint sb_watchpoint; + + // If the SBValue is not valid, there's no point in even trying to watch it. + lldb::ValueObjectSP value_sp(GetSP()); + TargetSP target_sp (GetTarget().GetSP()); + if (value_sp && target_sp) { - Mutex::Locker api_locker (target->GetAPIMutex()); - sb_watchpoint = WatchValue(read, write, false); + // Read and Write cannot both be false. + if (!read && !write) + return sb_watchpoint; + + // If the value is not in scope, don't try and watch and invalid value + if (!IsInScope()) + return sb_watchpoint; + + addr_t addr = GetLoadAddress(); + if (addr == LLDB_INVALID_ADDRESS) + return sb_watchpoint; + size_t byte_size = GetByteSize(); + if (byte_size == 0) + return sb_watchpoint; + + uint32_t watch_type = 0; + if (read) + watch_type |= LLDB_WATCH_TYPE_READ; + if (write) + watch_type |= LLDB_WATCH_TYPE_WRITE; + + WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type); + + if (watchpoint_sp) + { + sb_watchpoint.SetSP (watchpoint_sp); + Declaration decl; + if (value_sp->GetDeclaration (decl)) + { + if (decl.GetFile()) + { + StreamString ss; + // True to show fullpath for declaration file. + decl.DumpStopContext(&ss, true); + watchpoint_sp->SetDeclInfo(ss.GetString()); + } + } + } } - LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBValue(%p)::Watch (resolve_location=%i, read=%i, write=%i) => wp(%p)", - m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get()); return sb_watchpoint; } lldb::SBWatchpoint SBValue::WatchPointee (bool resolve_location, bool read, bool write) { - lldb::SBWatchpoint sb_watchpoint; - if (!m_opaque_sp) - return sb_watchpoint; - - Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get(); - if (target) - { - Mutex::Locker api_locker (target->GetAPIMutex()); - sb_watchpoint = WatchValue(read, write, true); - } - LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBValue(%p)::WatchPointee (resolve_location=%i, read=%i, write=%i) => wp(%p)", - m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get()); + SBWatchpoint sb_watchpoint; + if (IsInScope() && GetType().IsPointerType()) + sb_watchpoint = Dereference().Watch (resolve_location, read, write); return sb_watchpoint; } -// Helper function for SBValue::Watch() and SBValue::WatchPointee(). -SBWatchpoint -SBValue::WatchValue(bool read, bool write, bool watch_pointee) -{ - SBWatchpoint sb_wp_empty; - - // If the SBValue is not valid, there's no point in even trying to watch it. - if (!IsValid()) - return sb_wp_empty; - - // Read and Write cannot both be false. - if (!read && !write) - return sb_wp_empty; - - // If we are watching the pointee, check that the SBValue is a pointer type. - if (watch_pointee && !GetType().IsPointerType()) - return sb_wp_empty; - - TargetSP target_sp (GetTarget().GetSP()); - if (!target_sp) - return sb_wp_empty; - - StackFrameSP frame_sp (GetFrame().GetFrameSP()); - if (!frame_sp) - return sb_wp_empty; - - addr_t addr; - size_t size; - if (watch_pointee) { - addr = GetValueAsUnsigned(LLDB_INVALID_ADDRESS); - size = GetType().GetPointeeType().GetByteSize(); - } else { - addr = GetLoadAddress(); - size = GetByteSize(); - } - - // Sanity check the address and the size before calling Target::CreateWatchpoint(). - if (addr == LLDB_INVALID_ADDRESS || size == 0) - return sb_wp_empty; - - uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) | - (write ? LLDB_WATCH_TYPE_WRITE : 0); - WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, watch_type); - - if (wp_sp) { - // StackFrame::GetInScopeVariableList(true) to get file globals as well. - VariableListSP var_list_sp(frame_sp->GetInScopeVariableList(true)); - VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName())); - if (var_sp && var_sp->GetDeclaration().GetFile()) { - StreamString ss; - // True to show fullpath for declaration file. - var_sp->GetDeclaration().DumpStopContext(&ss, true); - wp_sp->SetDeclInfo(ss.GetString()); - } - } - return wp_sp; -} - Modified: lldb/trunk/source/API/SBValueList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValueList.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/API/SBValueList.cpp (original) +++ lldb/trunk/source/API/SBValueList.cpp Fri Feb 3 20:27:34 2012 @@ -110,10 +110,11 @@ void SBValueList::Append (const SBValue &val_obj) { - if (val_obj.get()) + ValueObjectSP value_sp (val_obj.GetSP()); + if (value_sp) { CreateIfNeeded (); - m_opaque_ap->Append (*val_obj); + m_opaque_ap->Append (value_sp); } } @@ -147,15 +148,19 @@ // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx); SBValue sb_value; + ValueObjectSP value_sp; if (m_opaque_ap.get()) - *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx); + { + value_sp = m_opaque_ap->GetValueObjectAtIndex (idx); + sb_value.SetSP (value_sp); + } if (log) { SBStream sstr; sb_value.GetDescription (sstr); log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')", - m_opaque_ap.get(), idx, sb_value.get(), sstr.GetData()); + m_opaque_ap.get(), idx, value_sp.get(), sstr.GetData()); } return sb_value; @@ -192,7 +197,7 @@ { SBValue sb_value; if (m_opaque_ap.get()) - *sb_value = m_opaque_ap->FindValueObjectByUID (uid); + sb_value.SetSP (m_opaque_ap->FindValueObjectByUID (uid)); return sb_value; } Modified: lldb/trunk/source/API/SBWatchpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBWatchpoint.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/API/SBWatchpoint.cpp (original) +++ lldb/trunk/source/API/SBWatchpoint.cpp Fri Feb 3 20:27:34 2012 @@ -69,15 +69,16 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); watch_id_t watch_id = LLDB_INVALID_WATCH_ID; - if (m_opaque_sp) - watch_id = m_opaque_sp->GetID(); + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) + watch_id = watchpoint_sp->GetID(); if (log) { if (watch_id == LLDB_INVALID_WATCH_ID) - log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", m_opaque_sp.get()); + log->Printf ("SBWatchpoint(%p)::GetID () => LLDB_INVALID_WATCH_ID", watchpoint_sp.get()); else - log->Printf ("SBWatchpoint(%p)::GetID () => %u", m_opaque_sp.get(), watch_id); + log->Printf ("SBWatchpoint(%p)::GetID () => %u", watchpoint_sp.get(), watch_id); } return watch_id; @@ -86,7 +87,8 @@ bool SBWatchpoint::IsValid() const { - if (m_opaque_sp && m_opaque_sp->GetError().Success()) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp && watchpoint_sp->GetError().Success()) return true; return false; } @@ -95,9 +97,10 @@ SBWatchpoint::GetError () { SBError sb_error; - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - sb_error.SetError(m_opaque_sp->GetError()); + sb_error.SetError(watchpoint_sp->GetError()); } return sb_error; } @@ -107,10 +110,11 @@ { int32_t hw_index = -1; - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - hw_index = m_opaque_sp->GetHardwareIndex(); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + hw_index = watchpoint_sp->GetHardwareIndex(); } return hw_index; @@ -121,10 +125,11 @@ { addr_t ret_addr = LLDB_INVALID_ADDRESS; - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - ret_addr = m_opaque_sp->GetLoadAddress(); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + ret_addr = watchpoint_sp->GetLoadAddress(); } return ret_addr; @@ -135,10 +140,11 @@ { size_t watch_size = 0; - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - watch_size = m_opaque_sp->GetByteSize(); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + watch_size = watchpoint_sp->GetByteSize(); } return watch_size; @@ -147,20 +153,22 @@ void SBWatchpoint::SetEnabled (bool enabled) { - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->GetTarget().DisableWatchpointByID(m_opaque_sp->GetID()); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + watchpoint_sp->GetTarget().DisableWatchpointByID(watchpoint_sp->GetID()); } } bool SBWatchpoint::IsEnabled () { - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->IsEnabled(); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + return watchpoint_sp->IsEnabled(); } else return false; @@ -170,15 +178,16 @@ SBWatchpoint::GetHitCount () { uint32_t count = 0; - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - count = m_opaque_sp->GetHitCount(); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + count = watchpoint_sp->GetHitCount(); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", m_opaque_sp.get(), count); + log->Printf ("SBWatchpoint(%p)::GetHitCount () => %u", watchpoint_sp.get(), count); return count; } @@ -186,10 +195,11 @@ uint32_t SBWatchpoint::GetIgnoreCount () { - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetIgnoreCount(); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + return watchpoint_sp->GetIgnoreCount(); } else return 0; @@ -198,20 +208,22 @@ void SBWatchpoint::SetIgnoreCount (uint32_t n) { - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetIgnoreCount (n); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + watchpoint_sp->SetIgnoreCount (n); } } const char * SBWatchpoint::GetCondition () { - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetConditionText (); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + return watchpoint_sp->GetConditionText (); } return NULL; } @@ -219,10 +231,11 @@ void SBWatchpoint::SetCondition (const char *condition) { - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetCondition (condition); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + watchpoint_sp->SetCondition (condition); } } @@ -231,10 +244,11 @@ { Stream &strm = description.ref(); - if (m_opaque_sp) + lldb::WatchpointSP watchpoint_sp(GetSP()); + if (watchpoint_sp) { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->GetDescription (&strm, level); + Mutex::Locker api_locker (watchpoint_sp->GetTarget().GetAPIMutex()); + watchpoint_sp->GetDescription (&strm, level); strm.EOL(); } else @@ -243,20 +257,20 @@ return true; } -lldb_private::Watchpoint * -SBWatchpoint::operator->() +void +SBWatchpoint::Clear () { - return m_opaque_sp.get(); + m_opaque_sp.reset(); } -lldb_private::Watchpoint * -SBWatchpoint::get() +lldb::WatchpointSP +SBWatchpoint::GetSP () const { - return m_opaque_sp.get(); + return m_opaque_sp; } -lldb::WatchpointSP & -SBWatchpoint::operator *() +void +SBWatchpoint::SetSP (const lldb::WatchpointSP &sp) { - return m_opaque_sp; + m_opaque_sp = sp; } Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Fri Feb 3 20:27:34 2012 @@ -1551,6 +1551,13 @@ return true; } +bool +ValueObject::GetDeclaration (Declaration &decl) +{ + decl.Clear(); + return false; +} + LanguageType ValueObject::GetObjectRuntimeLanguage () { @@ -3432,8 +3439,7 @@ ValueObjectSP ValueObject::Cast (const ClangASTType &clang_ast_type) { - ValueObjectSP valobj_sp(new ValueObjectCast (*this, GetName(), clang_ast_type)); - return valobj_sp; + return ValueObjectCast::Create (*this, GetName(), clang_ast_type); } ValueObjectSP Modified: lldb/trunk/source/Core/ValueObjectDynamicValue.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectDynamicValue.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectDynamicValue.cpp (original) +++ lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Fri Feb 3 20:27:34 2012 @@ -34,6 +34,14 @@ using namespace lldb_private; +lldb::ValueObjectSP +ValueObjectCast::Create (ValueObject &parent, + const ConstString &name, + const ClangASTType &cast_type) +{ + ValueObjectCast *cast_valobj_ptr = new ValueObjectCast (parent, name, cast_type); + return cast_valobj_ptr->GetSP(); +} ValueObjectCast::ValueObjectCast ( Modified: lldb/trunk/source/Core/ValueObjectVariable.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectVariable.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectVariable.cpp (original) +++ lldb/trunk/source/Core/ValueObjectVariable.cpp Fri Feb 3 20:27:34 2012 @@ -276,3 +276,14 @@ return m_variable_sp->GetSymbolContextScope(); return NULL; } + +bool +ValueObjectVariable::GetDeclaration (Declaration &decl) +{ + if (m_variable_sp) + { + decl = m_variable_sp->GetDeclaration(); + return true; + } + return false; +} Modified: lldb/trunk/source/Symbol/ClangASTType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTType.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTType.cpp Fri Feb 3 20:27:34 2012 @@ -182,10 +182,9 @@ } lldb::clang_type_t -ClangASTType::GetPointerType () +ClangASTType::GetPointerType () const { - return GetPointerType (m_ast, - m_type); + return GetPointerType (m_ast, m_type); } lldb::clang_type_t Modified: lldb/trunk/test/expression_command/test/TestExprs.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/test/TestExprs.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/expression_command/test/TestExprs.py (original) +++ lldb/trunk/test/expression_command/test/TestExprs.py Fri Feb 3 20:27:34 2012 @@ -94,7 +94,7 @@ self.assertTrue(breakpoint, VALID_BREAKPOINT) # Verify the breakpoint just created. - self.expect(repr(breakpoint), BREAKPOINT_CREATED, exe=False, + self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False, substrs = ['main.cpp', str(self.line)]) Modified: lldb/trunk/test/lang/c/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/array_types/TestArrayTypes.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/lang/c/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/lang/c/array_types/TestArrayTypes.py Fri Feb 3 20:27:34 2012 @@ -101,7 +101,7 @@ self.assertTrue(breakpoint, VALID_BREAKPOINT) # Sanity check the print representation of breakpoint. - bp = repr(breakpoint) + bp = str(breakpoint) self.expect(bp, msg="Breakpoint looks good", exe=False, substrs = ["file ='main.c'", "line = %d" % self.line, @@ -114,7 +114,7 @@ self.assertTrue(process, PROCESS_IS_VALID) # Sanity check the print representation of process. - proc = repr(process) + proc = str(process) self.expect(proc, msg="Process looks good", exe=False, substrs = ["state = stopped", "executable = a.out"]) @@ -127,7 +127,7 @@ stop_reason_to_str(thread.GetStopReason())) # Sanity check the print representation of thread. - thr = repr(thread) + thr = str(thread) self.expect(thr, "Thread looks good with stop reason = breakpoint", exe=False, substrs = ["tid = 0x%4.4x" % thread.GetThreadID()]) @@ -135,7 +135,7 @@ self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE) # The breakpoint should be resolved by now. - bp = repr(breakpoint) + bp = str(breakpoint) self.expect(bp, "Breakpoint looks good and is resolved", exe=False, substrs = ["file ='main.c'", "line = %d" % self.line, @@ -143,7 +143,7 @@ # Sanity check the print representation of frame. frame = thread.GetFrameAtIndex(0) - frm = repr(frame) + frm = str(frame) self.expect(frm, "Frame looks good with correct index %d" % frame.GetFrameID(), exe=False, @@ -152,7 +152,7 @@ # Lookup the "strings" string array variable and sanity check its print # representation. variable = frame.FindVariable("strings") - var = repr(variable) + var = str(variable) self.expect(var, "Variable for 'strings' looks good with correct name", exe=False, substrs = ["%s" % variable.GetName()]) self.DebugSBValue(variable) Modified: lldb/trunk/test/lang/cpp/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/class_types/TestClassTypes.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/lang/cpp/class_types/TestClassTypes.py (original) +++ lldb/trunk/test/lang/cpp/class_types/TestClassTypes.py Fri Feb 3 20:27:34 2012 @@ -114,7 +114,7 @@ self.assertTrue(breakpoint, VALID_BREAKPOINT) # Verify the breakpoint just created. - self.expect(repr(breakpoint), BREAKPOINT_CREATED, exe=False, + self.expect(str(breakpoint), BREAKPOINT_CREATED, exe=False, substrs = ['main.cpp', str(self.line)]) Modified: lldb/trunk/test/lang/cpp/stl/TestStdCXXDisassembly.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/stl/TestStdCXXDisassembly.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/lang/cpp/stl/TestStdCXXDisassembly.py (original) +++ lldb/trunk/test/lang/cpp/stl/TestStdCXXDisassembly.py Fri Feb 3 20:27:34 2012 @@ -43,7 +43,7 @@ process = target.GetProcess() # The process should be in a 'stopped' state. - self.expect(repr(process), STOPPED_DUE_TO_BREAKPOINT, exe=False, + self.expect(str(process), STOPPED_DUE_TO_BREAKPOINT, exe=False, substrs = ["a.out", "stopped"]) @@ -61,7 +61,7 @@ module = target.GetModuleAtIndex(i) fs = module.GetFileSpec() if (fs.GetFilename().startswith("libstdc++")): - lib_stdcxx = repr(fs) + lib_stdcxx = str(fs) break # At this point, lib_stdcxx is the full path to the stdc++ library and @@ -70,7 +70,7 @@ self.expect(fs.GetFilename(), "Libraray StdC++ is located", exe=False, substrs = ["libstdc++"]) - self.runCmd("image dump symtab %s" % repr(fs)) + self.runCmd("image dump symtab %s" % str(fs)) raw_output = self.res.GetOutput() # Now, look for every 'Code' symbol and feed its load address into the # command: 'disassemble -s load_address -e end_address', where the Modified: lldb/trunk/test/lldbutil.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/lldbutil.py (original) +++ lldb/trunk/test/lldbutil.py Fri Feb 3 20:27:34 2012 @@ -459,7 +459,7 @@ output = StringIO.StringIO() if string_buffer else sys.stdout - print >> output, "Stack traces for " + repr(process) + print >> output, "Stack traces for " + str(process) for thread in process: print >> output, print_stacktrace(thread, string_buffer=True) @@ -516,7 +516,7 @@ output = StringIO.StringIO() if string_buffer else sys.stdout - print >> output, "Register sets for " + repr(frame) + print >> output, "Register sets for " + str(frame) registerSet = frame.GetRegisters() # Return type of SBValueList. print >> output, "Frame registers (size of register set = %d):" % registerSet.GetSize() Modified: lldb/trunk/test/python_api/module_section/TestModuleAndSection.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/module_section/TestModuleAndSection.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/python_api/module_section/TestModuleAndSection.py (original) +++ lldb/trunk/test/python_api/module_section/TestModuleAndSection.py Fri Feb 3 20:27:34 2012 @@ -43,7 +43,7 @@ # Get the executable module at index 0. exe_module = target.GetModuleAtIndex(0) - print "Exe module: %s" % repr(exe_module) + print "Exe module: %s" % str(exe_module) print "Number of sections: %d" % exe_module.GetNumSections() INDENT = ' ' * 4 INDENT2 = INDENT * 2 @@ -52,14 +52,14 @@ print INDENT + "Number of subsections: %d" % sec.GetNumSubSections() if sec.GetNumSubSections() == 0: for sym in exe_module.symbol_in_section_iter(sec): - print INDENT + repr(sym) + print INDENT + str(sym) print INDENT + "symbol type: %s" % symbol_type_to_str(sym.GetType()) else: for subsec in sec: - print INDENT + repr(subsec) + print INDENT + str(subsec) # Now print the symbols belonging to the subsection.... for sym in exe_module.symbol_in_section_iter(subsec): - print INDENT2 + repr(sym) + print INDENT2 + str(sym) print INDENT2 + "symbol type: %s" % symbol_type_to_str(sym.GetType()) def module_and_section_boundary_condition(self): @@ -80,7 +80,7 @@ # Get the executable module at index 0. exe_module = target.GetModuleAtIndex(0) - print "Exe module: %s" % repr(exe_module) + print "Exe module: %s" % str(exe_module) print "Number of sections: %d" % exe_module.GetNumSections() # Boundary condition testings. Should not crash lldb! Modified: lldb/trunk/test/python_api/sbdata/TestSBData.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/sbdata/TestSBData.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/python_api/sbdata/TestSBData.py (original) +++ lldb/trunk/test/python_api/sbdata/TestSBData.py Fri Feb 3 20:27:34 2012 @@ -53,9 +53,9 @@ thread = process.GetThreadAtIndex(0) frame = thread.GetSelectedFrame() - + print frame foobar = frame.FindVariable('foobar') - + self.assertTrue(foobar.IsValid()) if self.TraceOn(): print foobar @@ -98,6 +98,7 @@ self.assertTrue(data.GetUnsignedInt32(error, offset) == 0, 'do not read beyond end') star_foobar = foobar.Dereference() + self.assertTrue(star_foobar.IsValid()) data = star_foobar.GetData() @@ -118,7 +119,7 @@ nothing = foobar.CreateValueFromAddress("nothing", foobar_addr, star_foobar.GetType().GetBasicType(lldb.eBasicTypeInvalid)) new_foobar = foobar.CreateValueFromAddress("f00", foobar_addr, star_foobar.GetType()) - + self.assertTrue(new_foobar.IsValid()) if self.TraceOn(): print new_foobar Modified: lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py?rev=149743&r1=149742&r2=149743&view=diff ============================================================================== --- lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py (original) +++ lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py Fri Feb 3 20:27:34 2012 @@ -68,7 +68,7 @@ substrs = [os.path.join(self.mydir, 'a.out')]) compileUnit = context.GetCompileUnit() - self.expect(repr(compileUnit), "The compile unit should match", exe=False, + self.expect(str(compileUnit), "The compile unit should match", exe=False, substrs = [os.path.join(self.mydir, 'main.c')]) function = context.GetFunction() From gclayton at apple.com Fri Feb 3 20:58:17 2012 From: gclayton at apple.com (Greg Clayton) Date: Sat, 04 Feb 2012 02:58:17 -0000 Subject: [Lldb-commits] [lldb] r149755 - in /lldb/trunk: include/lldb/API/SBAddress.h scripts/Python/interface/SBAddress.i scripts/Python/interface/SBModule.i scripts/Python/interface/SBSection.i source/API/SBAddress.cpp Message-ID: <20120204025818.032772A6C12C@llvm.org> Author: gclayton Date: Fri Feb 3 20:58:17 2012 New Revision: 149755 URL: http://llvm.org/viewvc/llvm-project?rev=149755&view=rev Log: Allow a SBAddress to be created from a SBSection and an offset. Changed the lldb.SBModule.section[] property to return a single section. Added a lldb.SBSection.addr property which returns an lldb.SBAddress object. Modified: lldb/trunk/include/lldb/API/SBAddress.h lldb/trunk/scripts/Python/interface/SBAddress.i lldb/trunk/scripts/Python/interface/SBModule.i lldb/trunk/scripts/Python/interface/SBSection.i lldb/trunk/source/API/SBAddress.cpp Modified: lldb/trunk/include/lldb/API/SBAddress.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBAddress.h?rev=149755&r1=149754&r2=149755&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBAddress.h (original) +++ lldb/trunk/include/lldb/API/SBAddress.h Fri Feb 3 20:58:17 2012 @@ -23,6 +23,8 @@ SBAddress (const lldb::SBAddress &rhs); + SBAddress (lldb::SBSection section, lldb::addr_t offset); + // Create an address by resolving a load address using the supplied target SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target); @@ -46,6 +48,9 @@ GetLoadAddress (const lldb::SBTarget &target) const; void + SetAddress (lldb::SBSection section, lldb::addr_t offset); + + void SetLoadAddress (lldb::addr_t load_addr, lldb::SBTarget &target); bool Modified: lldb/trunk/scripts/Python/interface/SBAddress.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBAddress.i?rev=149755&r1=149754&r2=149755&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBAddress.i (original) +++ lldb/trunk/scripts/Python/interface/SBAddress.i Fri Feb 3 20:58:17 2012 @@ -50,6 +50,9 @@ SBAddress (const lldb::SBAddress &rhs); + SBAddress (lldb::SBSection section, + lldb::addr_t offset); + %feature("docstring", " Create an address by resolving a load address using the supplied target. ") SBAddress; @@ -85,6 +88,11 @@ lldb::addr_t SBAddress::GetOffset (); + void + SetAddress (lldb::SBSection section, + lldb::addr_t offset); + + %feature("docstring", " //------------------------------------------------------------------ /// GetSymbolContext() and the following can lookup symbol information for a given address. Modified: lldb/trunk/scripts/Python/interface/SBModule.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBModule.i?rev=149755&r1=149754&r2=149755&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBModule.i (original) +++ lldb/trunk/scripts/Python/interface/SBModule.i Fri Feb 3 20:58:17 2012 @@ -320,12 +320,10 @@ if key < count: return self.sbmodule.GetSectionAtIndex(key) elif type(key) is str: - matches = [] for idx in range(count): section = self.sbmodule.GetSectionAtIndex(idx) if section.name == key: - matches.append(section) - return matches + return section elif isinstance(key, self.re_compile_type): matches = [] for idx in range(count): Modified: lldb/trunk/scripts/Python/interface/SBSection.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBSection.i?rev=149755&r1=149754&r2=149755&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBSection.i (original) +++ lldb/trunk/scripts/Python/interface/SBSection.i Fri Feb 3 20:58:17 2012 @@ -88,9 +88,15 @@ GetDescription (lldb::SBStream &description); %pythoncode %{ + def get_addr(self): + return SBAddress(self, 0) + __swig_getmethods__["name"] = GetName if _newclass: x = property(GetName, None) + __swig_getmethods__["addr"] = get_addr + if _newclass: x = property(get_addr, None) + __swig_getmethods__["file_addr"] = GetFileAddress if _newclass: x = property(GetFileAddress, None) Modified: lldb/trunk/source/API/SBAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=149755&r1=149754&r2=149755&view=diff ============================================================================== --- lldb/trunk/source/API/SBAddress.cpp (original) +++ lldb/trunk/source/API/SBAddress.cpp Fri Feb 3 20:58:17 2012 @@ -103,6 +103,12 @@ m_opaque_ap.reset (new AddressImpl(*rhs.m_opaque_ap.get())); } + +SBAddress::SBAddress (lldb::SBSection section, lldb::addr_t offset) : + m_opaque_ap(new AddressImpl (Address(section.GetSection(), offset))) +{ +} + // Create an address by resolving a load address using the supplied target SBAddress::SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target) : m_opaque_ap() @@ -142,6 +148,15 @@ } void +SBAddress::SetAddress (lldb::SBSection section, lldb::addr_t offset) +{ + Address &addr = ref(); + addr.SetSection (section.GetSection()); + addr.SetOffset (offset); +} + + +void SBAddress::SetAddress (const Address *lldb_object_ptr) { if (lldb_object_ptr) From scallanan at apple.com Sat Feb 4 02:49:35 2012 From: scallanan at apple.com (Sean Callanan) Date: Sat, 04 Feb 2012 08:49:35 -0000 Subject: [Lldb-commits] [lldb] r149775 - in /lldb/trunk: ./ include/lldb/Expression/ include/lldb/Symbol/ scripts/ source/Expression/ source/Plugins/SymbolFile/DWARF/ source/Symbol/ test/lang/c/bitfields/ Message-ID: <20120204084937.D74F92A6C12D@llvm.org> Author: spyffe Date: Sat Feb 4 02:49:35 2012 New Revision: 149775 URL: http://llvm.org/viewvc/llvm-project?rev=149775&view=rev Log: I have brought LLDB up-to-date with top of tree LLVM/Clang. This brings in several fixes, including: - Improvements in the Just-In-Time compiler's allocation of memory: the JIT now allocates memory in chunks of sections, improving its ability to generate relocations. I have revamped the RecordingMemoryManager to reflect these changes, as well as to get the memory allocation and data copying out fo the ClangExpressionParser code. Jim Grosbach wrote the updates to the JIT on the LLVM side. - A new ExternalASTSource interface to allow LLDB to report accurate structure layout information to Clang. Previously we could only report the sizes of fields, not their offsets. This meant that if data structures included field alignment directives, we could not communicate the necessary alignment to Clang and accesses to the data would fail. Now we can (and I have update the relevant test case). Thanks to Doug Gregor for implementing the Clang side of this fix. - The way Objective-C interfaces are completed by Clang has been made consistent with RecordDecls; with help from Doug Gregor and Greg Clayton I have ensured that this still works. - I have eliminated all local LLVM and Clang patches, committing the ones that are still relevant to LLVM and Clang as needed. I have tested the changes extensively locally, but please let me know if they cause any trouble for you. Removed: lldb/trunk/scripts/clang.DebuggerCastResultToId.diff lldb/trunk/scripts/clang.complete-type-being-converted.diff lldb/trunk/scripts/clang.complete-type-being-laid-out.diff lldb/trunk/scripts/clang.complete-type-ivar-lookup.diff lldb/trunk/scripts/clang.instantiate-complete-type.diff lldb/trunk/scripts/clang.is-being-completed-from-lexical-storage.diff lldb/trunk/scripts/clang.require-complete-type.diff lldb/trunk/scripts/llvm.communicate-triple.diff lldb/trunk/scripts/llvm.delete-target-machine.diff Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h lldb/trunk/include/lldb/Symbol/ClangASTImporter.h lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h lldb/trunk/llvm.zip lldb/trunk/scripts/build-llvm.pl lldb/trunk/source/Expression/ClangASTSource.cpp lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp lldb/trunk/source/Expression/ClangExpressionParser.cpp lldb/trunk/source/Expression/ClangPersistentVariables.cpp lldb/trunk/source/Expression/IRForTarget.cpp lldb/trunk/source/Expression/IRInterpreter.cpp lldb/trunk/source/Expression/RecordingMemoryManager.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Symbol/ClangASTContext.cpp lldb/trunk/source/Symbol/ClangASTImporter.cpp lldb/trunk/source/Symbol/ClangASTType.cpp lldb/trunk/source/Symbol/ClangExternalASTSourceCallbacks.cpp lldb/trunk/test/lang/c/bitfields/TestBitfields.py lldb/trunk/test/lang/c/bitfields/main.c Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original) +++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Sat Feb 4 02:49:35 2012 @@ -121,6 +121,47 @@ llvm::SmallVectorImpl &Decls); //------------------------------------------------------------------ + /// Specify the layout of the contents of a RecordDecl. + /// + /// @param[in] Record + /// The record (in the parser's AST context) that needs to be + /// laid out. + /// + /// @param[out] Size + /// The total size of the record in bits. + /// + /// @param[out] Alignment + /// The alignment of the record in bits. + /// + /// @param[in] FieldOffsets + /// A map that must be populated with pairs of the record's + /// fields (in the parser's AST context) and their offsets + /// (measured in bits). + /// + /// @param[in] BaseOffsets + /// A map that must be populated with pairs of the record's + /// C++ concrete base classes (in the parser's AST context, + /// and only if the record is a CXXRecordDecl and has base + /// classes) and their offsets (measured in bytes). + /// + /// @param[in] VirtualBaseOffsets + /// A map that must be populated with pairs of the record's + /// C++ virtual base classes (in the parser's AST context, + /// and only if the record is a CXXRecordDecl and has base + /// classes) and their offsets (measured in bytes). + /// + /// @return + /// True <=> the layout is valid. + //----------------------------------------------------------------- + bool + layoutRecordType(const clang::RecordDecl *Record, + uint64_t &Size, + uint64_t &Alignment, + llvm::DenseMap &FieldOffsets, + llvm::DenseMap &BaseOffsets, + llvm::DenseMap &VirtualBaseOffsets); + + //------------------------------------------------------------------ /// Complete a TagDecl. /// /// @param[in] Tag @@ -233,6 +274,22 @@ { return m_original.CompleteType(Class); } + + bool + layoutRecordType(const clang::RecordDecl *Record, + uint64_t &Size, + uint64_t &Alignment, + llvm::DenseMap &FieldOffsets, + llvm::DenseMap &BaseOffsets, + llvm::DenseMap &VirtualBaseOffsets) + { + return m_original.layoutRecordType(Record, + Size, + Alignment, + FieldOffsets, + BaseOffsets, + VirtualBaseOffsets); + } void StartTranslationUnit (clang::ASTConsumer *Consumer) { @@ -301,7 +358,7 @@ FindObjCMethodDecls (NameSearchContext &context); //------------------------------------------------------------------ - /// Find all Objective-C properties with a given name. + /// Find all Objective-C properties and ivars with a given name. /// /// @param[in] context /// The NameSearchContext that can construct Decls for this name. @@ -309,7 +366,7 @@ /// is the containing object. //------------------------------------------------------------------ void - FindObjCPropertyDecls (NameSearchContext &context); + FindObjCPropertyAndIvarDecls (NameSearchContext &context); //------------------------------------------------------------------ /// A wrapper for ClangASTContext::CopyType that sets a flag that Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Sat Feb 4 02:49:35 2012 @@ -503,6 +503,10 @@ bool transient, bool maybe_make_load); + + void + RemoveResultVariable (const ConstString &name); + //------------------------------------------------------------------ /// [Used by CommandObjectExpression] Materialize the entire struct /// at a given address, which should be aligned as specified by Modified: lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h Sat Feb 4 02:49:35 2012 @@ -375,8 +375,6 @@ m_variables.push_back(var_sp); return var_sp; } - - lldb::ClangExpressionVariableSP CreateVariable (ExecutionContextScope *exe_scope, @@ -394,6 +392,21 @@ } void + RemoveVariable (lldb::ClangExpressionVariableSP var_sp) + { + for (std::vector::iterator vi = m_variables.begin(), ve = m_variables.end(); + vi != ve; + ++vi) + { + if (vi->get() == var_sp.get()) + { + m_variables.erase(vi); + return; + } + } + } + + void Clear() { m_variables.clear(); Modified: lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h (original) +++ lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h Sat Feb 4 02:49:35 2012 @@ -52,6 +52,9 @@ //---------------------------------------------------------------------- ConstString GetNextPersistentVariableName (); + + void + RemovePersistentVariable (lldb::ClangExpressionVariableSP variable); void RegisterPersistentType (const ConstString &name, Modified: lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h (original) +++ lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h Sat Feb 4 02:49:35 2012 @@ -152,6 +152,43 @@ /// Allocated space. //------------------------------------------------------------------ virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment); + + //------------------------------------------------------------------ + /// Allocate space for executable code, and add it to the + /// m_spaceBlocks map + /// + /// @param[in] Size + /// The size of the area. + /// + /// @param[in] Alignment + /// The required alignment of the area. + /// + /// @param[in] SectionID + /// A unique identifier for the section. + /// + /// @return + /// Allocated space. + //------------------------------------------------------------------ + virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, + unsigned SectionID); + + //------------------------------------------------------------------ + /// Allocate space for data, and add it to the m_spaceBlocks map + /// + /// @param[in] Size + /// The size of the area. + /// + /// @param[in] Alignment + /// The required alignment of the area. + /// + /// @param[in] SectionID + /// A unique identifier for the section. + /// + /// @return + /// Allocated space. + //------------------------------------------------------------------ + virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, + unsigned SectionID); //------------------------------------------------------------------ /// Allocate space for a global variable, and add it to the @@ -246,7 +283,7 @@ } //------------------------------------------------------------------ - /// [Convenience method for ClangExpression] Look up the object in + /// [Convenience method for ClangExpressionParser] Look up the object in /// m_address_map that contains a given address, find where it was /// copied to, and return the remote address at the same offset into /// the copied entity @@ -261,7 +298,7 @@ GetRemoteAddressForLocal (lldb::addr_t local_address); //------------------------------------------------------------------ - /// [Convenience method for ClangExpression] Look up the object in + /// [Convenience method for ClangExpressionParser] Look up the object in /// m_address_map that contains a given address, find where it was /// copied to, and return its address range in the target process /// @@ -271,61 +308,82 @@ /// @return /// The range of the containing object in the target process. //------------------------------------------------------------------ - std::pair + typedef std::pair AddrRange; + AddrRange GetRemoteRangeForLocal (lldb::addr_t local_address); + + //------------------------------------------------------------------ + /// [Convenience method for ClangExpressionParser] Commit all allocations + /// to the process and record where they were stored. + /// + /// @param[in] process + /// The process to allocate memory in. + /// + /// @return + /// True <=> all allocations were performed successfully. + /// This method will attempt to free allocated memory if the + /// operation fails. + //------------------------------------------------------------------ + bool + CommitAllocations (Process &process); + + //------------------------------------------------------------------ + /// [Convenience method for ClangExpressionParser] Write the contents + /// of all allocations to the process. + /// + /// @param[in] local_address + /// The process containing the allocations. + /// + /// @return + /// True <=> all allocations were performed successfully. + //------------------------------------------------------------------ + bool + WriteData (Process &process); private: std::auto_ptr m_default_mm_ap; ///< The memory allocator to use in actually creating space. All calls are passed through to it. - std::map m_functions; ///< A map from function base addresses to their end addresses. - std::map m_spaceBlocks; ///< A map from the base addresses of generic allocations to their sizes. - std::map m_stubs; ///< A map from the base addresses of stubs to their sizes. - std::map m_globals; ///< A map from the base addresses of globals to their sizes. - std::map m_exception_tables; ///< A map from the base addresses of exception tables to their end addresses. lldb::LogSP m_log; ///< The log to use when printing log messages. May be NULL. //---------------------------------------------------------------------- - /// @class LocalToRemoteAddressRange RecordingMemoryManager.h "lldb/Expression/RecordingMemoryManager.h" - /// @brief A record of an allocated region that has been copied into the target + /// @class Allocation RecordingMemoryManager.h "lldb/Expression/RecordingMemoryManager.h" + /// @brief A record of a region that has been allocated by the JIT. /// /// The RecordingMemoryManager makes records of all regions that need copying; - /// then, ClangExpression copies these regions into the target. It records - /// what was copied where in records of type LocalToRemoteAddressRange. + /// upon requests, it allocates and //---------------------------------------------------------------------- - struct LocalToRemoteAddressRange + struct Allocation { - lldb::addr_t m_local_start; ///< The base address of the local allocation - size_t m_size; ///< The size of the allocation - lldb::addr_t m_remote_start; ///< The base address of the remote allocation + lldb::addr_t m_remote_allocation;///< The (unaligned) base for the remote allocation + lldb::addr_t m_remote_start; ///< The base address of the remote allocation + uintptr_t m_local_start; ///< The base address of the local allocation + uintptr_t m_size; ///< The size of the allocation + unsigned m_section_id; ///< The ID of the section + unsigned m_alignment; ///< The required alignment for the allocation + bool m_executable; ///< True <=> the allocation must be executable in the target + bool m_allocated; ///< True <=> the allocation has been propagated to the target + static const unsigned eSectionIDNone = (unsigned)-1; + //------------------------------------------------------------------ /// Constructor //------------------------------------------------------------------ - LocalToRemoteAddressRange (lldb::addr_t lstart, size_t size, lldb::addr_t rstart) : - m_local_start (lstart), - m_size (size), - m_remote_start (rstart) - {} - + Allocation () : + m_remote_allocation(0), + m_remote_start(0), + m_local_start(0), + m_size(0), + m_section_id(eSectionIDNone), + m_alignment(0), + m_executable(false), + m_allocated(false) + { + } + + void dump (lldb::LogSP log); }; - //------------------------------------------------------------------ - /// Add a range to the list of copied ranges. - /// - /// @param[in] lstart - /// The base address of the local allocation. - /// - /// @param[in] size - /// The size of the allocation. - /// - /// @param[in] rstart - /// The base address of the remote allocation. - //------------------------------------------------------------------ - void - AddToLocalToRemoteMap (lldb::addr_t lstart, size_t size, lldb::addr_t rstart); - - std::vector m_address_map; ///< The base address of the remote allocation - - friend class ClangExpressionParser; + typedef std::vector AllocationList; + AllocationList m_allocations; ///< The base address of the remote allocation }; } // namespace lldb_private Modified: lldb/trunk/include/lldb/Symbol/ClangASTImporter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTImporter.h?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangASTImporter.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangASTImporter.h Sat Feb 4 02:49:35 2012 @@ -57,6 +57,9 @@ DeportDecl (clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx, clang::Decl *decl); + + void + CompleteDecl (clang::Decl *decl); bool CompleteTagDecl (clang::TagDecl *decl); Modified: lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h Sat Feb 4 02:49:35 2012 @@ -122,7 +122,14 @@ virtual void CompleteType (clang::ObjCInterfaceDecl *objc_decl); - + + bool + layoutRecordType(const clang::RecordDecl *Record, + uint64_t &Size, + uint64_t &Alignment, + llvm::DenseMap &FieldOffsets, + llvm::DenseMap &BaseOffsets, + llvm::DenseMap &VirtualBaseOffsets); void SetExternalSourceCallbacks (CompleteTagDeclCallback tag_decl_callback, CompleteObjCInterfaceDeclCallback objc_decl_callback, Modified: lldb/trunk/llvm.zip URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/llvm.zip?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== Binary files - no diff available. Modified: lldb/trunk/scripts/build-llvm.pl URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/build-llvm.pl?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/scripts/build-llvm.pl (original) +++ lldb/trunk/scripts/build-llvm.pl Sat Feb 4 02:49:35 2012 @@ -21,8 +21,8 @@ our $llvm_configuration = $ENV{LLVM_CONFIGURATION}; -our $llvm_revision = "146622"; -our $clang_revision = "146622"; +our $llvm_revision = "149773"; +our $clang_revision = "149773"; our $SRCROOT = "$ENV{SRCROOT}"; our $llvm_dstroot_zip = "$SRCROOT/llvm.zip"; Removed: lldb/trunk/scripts/clang.DebuggerCastResultToId.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/clang.DebuggerCastResultToId.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/clang.DebuggerCastResultToId.diff (original) +++ lldb/trunk/scripts/clang.DebuggerCastResultToId.diff (removed) @@ -1,25 +0,0 @@ -Index: include/clang/Basic/LangOptions.def -=================================================================== ---- include/clang/Basic/LangOptions.def (revision 146622) -+++ include/clang/Basic/LangOptions.def (working copy) -@@ -121,6 +121,7 @@ - BENIGN_LANGOPT(InlineVisibilityHidden , 1, 0, "hidden default visibility for inline C++ methods") - BENIGN_LANGOPT(ParseUnknownAnytype, 1, 0, "__unknown_anytype") - BENIGN_LANGOPT(DebuggerSupport , 1, 0, "debugger support") -+BENIGN_LANGOPT(DebuggerCastResultToId, 1, 0, "for 'po' in the debugger, cast the result to id if it is of unknown type") - BENIGN_LANGOPT(AddressSanitizer , 1, 0, "AddressSanitizer enabled") - - BENIGN_LANGOPT(SpellChecking , 1, 1, "spell-checking") -Index: lib/Sema/SemaExprCXX.cpp -=================================================================== ---- lib/Sema/SemaExprCXX.cpp (revision 146622) -+++ lib/Sema/SemaExprCXX.cpp (working copy) -@@ -4675,7 +4675,7 @@ - return ExprError(); - - // Top-level message sends default to 'id' when we're in a debugger. -- if (getLangOptions().DebuggerSupport && -+ if (getLangOptions().DebuggerCastResultToId && - FullExpr.get()->getType() == Context.UnknownAnyTy && - isa(FullExpr.get())) { - FullExpr = forceUnknownAnyToType(FullExpr.take(), Context.getObjCIdType()); Removed: lldb/trunk/scripts/clang.complete-type-being-converted.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/clang.complete-type-being-converted.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/clang.complete-type-being-converted.diff (original) +++ lldb/trunk/scripts/clang.complete-type-being-converted.diff (removed) @@ -1,14 +0,0 @@ -Index: lib/CodeGen/CodeGenTypes.cpp -=================================================================== ---- lib/CodeGen/CodeGenTypes.cpp (revision 146622) -+++ lib/CodeGen/CodeGenTypes.cpp (working copy) -@@ -113,6 +113,9 @@ - static bool - isSafeToConvert(const RecordDecl *RD, CodeGenTypes &CGT, - llvm::SmallPtrSet &AlreadyChecked) { -+ if (RD->hasExternalLexicalStorage() && !RD->getDefinition()) -+ RD->getASTContext().getExternalSource()->CompleteType(const_cast(RD)); -+ - // If we have already checked this type (maybe the same type is used by-value - // multiple times in multiple structure fields, don't check again. - if (!AlreadyChecked.insert(RD)) return true; Removed: lldb/trunk/scripts/clang.complete-type-being-laid-out.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/clang.complete-type-being-laid-out.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/clang.complete-type-being-laid-out.diff (original) +++ lldb/trunk/scripts/clang.complete-type-being-laid-out.diff (removed) @@ -1,15 +0,0 @@ -Index: lib/AST/RecordLayoutBuilder.cpp -=================================================================== ---- lib/AST/RecordLayoutBuilder.cpp (revision 146622) -+++ lib/AST/RecordLayoutBuilder.cpp (working copy) -@@ -2062,6 +2062,10 @@ - // as soon as we begin to parse the definition. That definition is - // not a complete definition (which is what isDefinition() tests) - // until we *finish* parsing the definition. -+ -+ if (D->hasExternalLexicalStorage() && !D->getDefinition()) -+ getExternalSource()->CompleteType(const_cast(D)); -+ - D = D->getDefinition(); - assert(D && "Cannot get layout of forward declarations!"); - assert(D->isCompleteDefinition() && "Cannot layout type before complete!"); Removed: lldb/trunk/scripts/clang.complete-type-ivar-lookup.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/clang.complete-type-ivar-lookup.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/clang.complete-type-ivar-lookup.diff (original) +++ lldb/trunk/scripts/clang.complete-type-ivar-lookup.diff (removed) @@ -1,19 +0,0 @@ -Index: lib/AST/DeclObjC.cpp -=================================================================== ---- lib/AST/DeclObjC.cpp (revision 146622) -+++ lib/AST/DeclObjC.cpp (working copy) -@@ -244,11 +244,11 @@ - - ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, - ObjCInterfaceDecl *&clsDeclared) { -- if (ExternallyCompleted) -- LoadExternalDefinition(); -- - ObjCInterfaceDecl* ClassDecl = this; - while (ClassDecl != NULL) { -+ if (ClassDecl->ExternallyCompleted) -+ ClassDecl->LoadExternalDefinition(); -+ - if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) { - clsDeclared = ClassDecl; - return I; Removed: lldb/trunk/scripts/clang.instantiate-complete-type.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/clang.instantiate-complete-type.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/clang.instantiate-complete-type.diff (original) +++ lldb/trunk/scripts/clang.instantiate-complete-type.diff (removed) @@ -1,15 +0,0 @@ -Index: lib/Sema/SemaTemplateInstantiate.cpp -=================================================================== ---- lib/Sema/SemaTemplateInstantiate.cpp (revision 145552) -+++ lib/Sema/SemaTemplateInstantiate.cpp (working copy) -@@ -1683,6 +1683,10 @@ - TemplateSpecializationKind TSK, - bool Complain) { - bool Invalid = false; -+ -+ RequireCompleteType(Pattern->getLocation(), -+ QualType(Pattern->getTypeForDecl(), 0), -+ diag::err_incomplete_type); - - CXXRecordDecl *PatternDef - = cast_or_null(Pattern->getDefinition()); Removed: lldb/trunk/scripts/clang.is-being-completed-from-lexical-storage.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/clang.is-being-completed-from-lexical-storage.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/clang.is-being-completed-from-lexical-storage.diff (original) +++ lldb/trunk/scripts/clang.is-being-completed-from-lexical-storage.diff (removed) @@ -1,78 +0,0 @@ -Index: lib/AST/ASTImporter.cpp -=================================================================== ---- lib/AST/ASTImporter.cpp (revision 146622) -+++ lib/AST/ASTImporter.cpp (working copy) -@@ -2300,7 +2300,8 @@ - - if (RecordDecl *FoundRecord = dyn_cast(Found)) { - if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { -- if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { -+ if (FoundDef->isBeingCompletedFromLexicalStorage() || -+ !D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { - // The record types structurally match, or the "from" translation - // unit only had a forward declaration anyway; call it the same - // function. -Index: lib/AST/Decl.cpp -=================================================================== ---- lib/AST/Decl.cpp (revision 146622) -+++ lib/AST/Decl.cpp (working copy) -@@ -2421,8 +2421,14 @@ - ExternalASTSource::Deserializing TheFields(Source); - - SmallVector Decls; -- LoadedFieldsFromExternalStorage = true; -- switch (Source->FindExternalLexicalDeclsBy(this, Decls)) { -+ LoadedFieldsFromExternalStorage = true; -+ -+ setIsBeingCompletedFromLexicalStorage(true); -+ ExternalLoadResult LoadResult = -+ Source->FindExternalLexicalDeclsBy(this, Decls); -+ setIsBeingCompletedFromLexicalStorage(false); -+ -+ switch (LoadResult) { - case ELR_Success: - break; - -Index: include/clang/AST/DeclBase.h -=================================================================== ---- include/clang/AST/DeclBase.h (revision 146622) -+++ include/clang/AST/DeclBase.h (working copy) -@@ -836,6 +836,12 @@ - /// storage that contains additional declarations that are visible - /// in this context. - mutable unsigned ExternalVisibleStorage : 1; -+ -+ /// \brief True if this declaration context is currently having -+ /// declarations added from its external lexical storage. This flag -+ /// is intended to prevent One Definition Rule checking as the -+ /// declarations are imported. -+ mutable unsigned IsBeingCompletedFromLexicalStorage : 1; - - /// \brief Pointer to the data structure used to lookup declarations - /// within this context (or a DependentStoredDeclsMap if this is a -@@ -863,8 +869,8 @@ - - DeclContext(Decl::Kind K) - : DeclKind(K), ExternalLexicalStorage(false), -- ExternalVisibleStorage(false), LookupPtr(0), FirstDecl(0), -- LastDecl(0) { } -+ ExternalVisibleStorage(false), IsBeingCompletedFromLexicalStorage(false), -+ LookupPtr(0), FirstDecl(0), LastDecl(0) { } - - public: - ~DeclContext(); -@@ -1368,6 +1374,14 @@ - ExternalVisibleStorage = ES; - } - -+ bool isBeingCompletedFromLexicalStorage() const { -+ return IsBeingCompletedFromLexicalStorage; -+ } -+ -+ void setIsBeingCompletedFromLexicalStorage(bool IBC) const { -+ IsBeingCompletedFromLexicalStorage = IBC; -+ } -+ - /// \brief Determine whether the given declaration is stored in the list of - /// declarations lexically within this context. - bool isDeclInLexicalTraversal(const Decl *D) const { Removed: lldb/trunk/scripts/clang.require-complete-type.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/clang.require-complete-type.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/clang.require-complete-type.diff (original) +++ lldb/trunk/scripts/clang.require-complete-type.diff (removed) @@ -1,75 +0,0 @@ -Index: lib/Sema/SemaType.cpp -=================================================================== ---- lib/Sema/SemaType.cpp (revision 145552) -+++ lib/Sema/SemaType.cpp (working copy) -@@ -4065,6 +4065,34 @@ - if (!T->isIncompleteType()) - return false; - -+ const TagType *Tag = T->getAs(); -+ const ObjCInterfaceType *IFace = 0; -+ -+ if (Tag) { -+ // Avoid diagnosing invalid decls as incomplete. -+ if (Tag->getDecl()->isInvalidDecl()) -+ return true; -+ -+ // Give the external AST source a chance to complete the type. -+ if (Tag->getDecl()->hasExternalLexicalStorage()) { -+ Context.getExternalSource()->CompleteType(Tag->getDecl()); -+ if (!Tag->isIncompleteType()) -+ return false; -+ } -+ } -+ else if ((IFace = T->getAs())) { -+ // Avoid diagnosing invalid decls as incomplete. -+ if (IFace->getDecl()->isInvalidDecl()) -+ return true; -+ -+ // Give the external AST source a chance to complete the type. -+ if (IFace->getDecl()->hasExternalLexicalStorage()) { -+ Context.getExternalSource()->CompleteType(IFace->getDecl()); -+ if (!IFace->isIncompleteType()) -+ return false; -+ } -+ } -+ - // If we have a class template specialization or a class member of a - // class template specialization, or an array with known size of such, - // try to instantiate it. -@@ -4096,35 +4124,7 @@ - - if (diag == 0) - return true; -- -- const TagType *Tag = T->getAs(); -- const ObjCInterfaceType *IFace = 0; -- -- if (Tag) { -- // Avoid diagnosing invalid decls as incomplete. -- if (Tag->getDecl()->isInvalidDecl()) -- return true; -- -- // Give the external AST source a chance to complete the type. -- if (Tag->getDecl()->hasExternalLexicalStorage()) { -- Context.getExternalSource()->CompleteType(Tag->getDecl()); -- if (!Tag->isIncompleteType()) -- return false; -- } -- } -- else if ((IFace = T->getAs())) { -- // Avoid diagnosing invalid decls as incomplete. -- if (IFace->getDecl()->isInvalidDecl()) -- return true; - -- // Give the external AST source a chance to complete the type. -- if (IFace->getDecl()->hasExternalLexicalStorage()) { -- Context.getExternalSource()->CompleteType(IFace->getDecl()); -- if (!IFace->isIncompleteType()) -- return false; -- } -- } -- - // We have an incomplete type. Produce a diagnostic. - Diag(Loc, PD) << T; - Removed: lldb/trunk/scripts/llvm.communicate-triple.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/llvm.communicate-triple.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/llvm.communicate-triple.diff (original) +++ lldb/trunk/scripts/llvm.communicate-triple.diff (removed) @@ -1,199 +0,0 @@ -Index: lib/MC/MCDisassembler/EDOperand.cpp -=================================================================== ---- lib/MC/MCDisassembler/EDOperand.cpp (revision 146622) -+++ lib/MC/MCDisassembler/EDOperand.cpp (working copy) -@@ -30,8 +30,10 @@ - MCOpIndex(mcOpIndex) { - unsigned int numMCOperands = 0; - -- if (Disassembler.Key.Arch == Triple::x86 || -- Disassembler.Key.Arch == Triple::x86_64) { -+ Triple::ArchType arch = Disassembler.TgtTriple.getArch(); -+ -+ if (arch == Triple::x86 || -+ arch == Triple::x86_64) { - uint8_t operandType = inst.ThisInstInfo->operandTypes[opIndex]; - - switch (operandType) { -@@ -54,8 +56,8 @@ - break; - } - } -- else if (Disassembler.Key.Arch == Triple::arm || -- Disassembler.Key.Arch == Triple::thumb) { -+ else if (arch == Triple::arm || -+ arch == Triple::thumb) { - uint8_t operandType = inst.ThisInstInfo->operandTypes[opIndex]; - - switch (operandType) { -@@ -126,7 +128,9 @@ - void *arg) { - uint8_t operandType = Inst.ThisInstInfo->operandTypes[OpIndex]; - -- switch (Disassembler.Key.Arch) { -+ Triple::ArchType arch = Disassembler.TgtTriple.getArch(); -+ -+ switch (arch) { - default: - return -1; - case Triple::x86: -@@ -168,7 +172,7 @@ - - unsigned segmentReg = Inst.Inst->getOperand(MCOpIndex+4).getReg(); - -- if (segmentReg != 0 && Disassembler.Key.Arch == Triple::x86_64) { -+ if (segmentReg != 0 && arch == Triple::x86_64) { - unsigned fsID = Disassembler.registerIDWithName("FS"); - unsigned gsID = Disassembler.registerIDWithName("GS"); - -Index: lib/MC/MCDisassembler/EDDisassembler.cpp -=================================================================== ---- lib/MC/MCDisassembler/EDDisassembler.cpp (revision 146622) -+++ lib/MC/MCDisassembler/EDDisassembler.cpp (working copy) -@@ -98,16 +98,23 @@ - - EDDisassembler *EDDisassembler::getDisassembler(Triple::ArchType arch, - AssemblySyntax syntax) { -+ const char *triple = tripleFromArch(arch); -+ return getDisassembler(StringRef(triple), syntax); -+} -+ -+EDDisassembler *EDDisassembler::getDisassembler(StringRef str, -+ AssemblySyntax syntax) { - CPUKey key; -- key.Arch = arch; -+ key.Triple = str.str(); - key.Syntax = syntax; - - EDDisassembler::DisassemblerMap_t::iterator i = sDisassemblers.find(key); -- -+ - if (i != sDisassemblers.end()) { -- return i->second; -- } else { -- EDDisassembler* sdd = new EDDisassembler(key); -+ return i->second; -+ } -+ else { -+ EDDisassembler *sdd = new EDDisassembler(key); - if (!sdd->valid()) { - delete sdd; - return NULL; -@@ -119,10 +126,7 @@ - } - - return NULL; --} -- --EDDisassembler *EDDisassembler::getDisassembler(StringRef str, -- AssemblySyntax syntax) { -+ - return getDisassembler(Triple(str).getArch(), syntax); - } - -@@ -130,21 +134,20 @@ - Valid(false), - HasSemantics(false), - ErrorStream(nulls()), -- Key(key) { -- const char *triple = tripleFromArch(key.Arch); -- -- if (!triple) -+ Key(key), -+ TgtTriple(key.Triple.c_str()) { -+ if (TgtTriple.getArch() == Triple::InvalidArch) - return; - -- LLVMSyntaxVariant = getLLVMSyntaxVariant(key.Arch, key.Syntax); -+ LLVMSyntaxVariant = getLLVMSyntaxVariant(TgtTriple.getArch(), key.Syntax); - - if (LLVMSyntaxVariant < 0) - return; - -- std::string tripleString(triple); -+ std::string tripleString(key.Triple); - std::string errorString; - -- Tgt = TargetRegistry::lookupTarget(tripleString, -+ Tgt = TargetRegistry::lookupTarget(key.Triple, - errorString); - - if (!Tgt) -@@ -263,7 +266,7 @@ - RegRMap[registerName] = registerIndex; - } - -- switch (Key.Arch) { -+ switch (TgtTriple.getArch()) { - default: - break; - case Triple::x86: -@@ -331,7 +334,7 @@ - const std::string &str) { - int ret = 0; - -- switch (Key.Arch) { -+ switch (TgtTriple.getArch()) { - default: - return -1; - case Triple::x86: -@@ -356,8 +359,7 @@ - context, *streamer, - *AsmInfo)); - -- StringRef triple = tripleFromArch(Key.Arch); -- OwningPtr STI(Tgt->createMCSubtargetInfo(triple, "", "")); -+ OwningPtr STI(Tgt->createMCSubtargetInfo(Key.Triple.c_str(), "", "")); - OwningPtr - TargetParser(Tgt->createMCAsmParser(*STI, *genericParser)); - -Index: lib/MC/MCDisassembler/EDDisassembler.h -=================================================================== ---- lib/MC/MCDisassembler/EDDisassembler.h (revision 146622) -+++ lib/MC/MCDisassembler/EDDisassembler.h (working copy) -@@ -25,6 +25,7 @@ - - #include - #include -+#include - #include - - namespace llvm { -@@ -74,21 +75,21 @@ - /// pair - struct CPUKey { - /// The architecture type -- llvm::Triple::ArchType Arch; -+ std::string Triple; - - /// The assembly syntax - AssemblySyntax Syntax; - - /// operator== - Equality operator - bool operator==(const CPUKey &key) const { -- return (Arch == key.Arch && -+ return (Triple == key.Triple && - Syntax == key.Syntax); - } - - /// operator< - Less-than operator - bool operator<(const CPUKey &key) const { -- return ((Arch < key.Arch) || -- ((Arch == key.Arch) && Syntax < (key.Syntax))); -+ return ((Triple < key.Triple) || -+ ((Triple == key.Triple) && Syntax < (key.Syntax))); - } - }; - -@@ -126,8 +127,10 @@ - /// The stream to write errors to - llvm::raw_ostream &ErrorStream; - -- /// The architecture/syntax pair for the current architecture -+ /// The triple/syntax pair for the current architecture - CPUKey Key; -+ /// The Triple fur the current architecture -+ Triple TgtTriple; - /// The LLVM target corresponding to the disassembler - const llvm::Target *Tgt; - /// The assembly information for the target architecture Removed: lldb/trunk/scripts/llvm.delete-target-machine.diff URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/llvm.delete-target-machine.diff?rev=149774&view=auto ============================================================================== --- lldb/trunk/scripts/llvm.delete-target-machine.diff (original) +++ lldb/trunk/scripts/llvm.delete-target-machine.diff (removed) @@ -1,12 +0,0 @@ -Index: lib/ExecutionEngine/MCJIT/MCJIT.cpp -=================================================================== ---- lib/ExecutionEngine/MCJIT/MCJIT.cpp (revision 146622) -+++ lib/ExecutionEngine/MCJIT/MCJIT.cpp (working copy) -@@ -85,6 +85,7 @@ - - MCJIT::~MCJIT() { - delete MemMgr; -+ delete TM; - } - - void *MCJIT::getPointerToBasicBlock(BasicBlock *BB) { Modified: lldb/trunk/source/Expression/ClangASTSource.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangASTSource.cpp (original) +++ lldb/trunk/source/Expression/ClangASTSource.cpp Sat Feb 4 02:49:35 2012 @@ -9,6 +9,7 @@ #include "clang/AST/ASTContext.h" +#include "clang/AST/RecordLayout.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" @@ -448,7 +449,7 @@ } else if (isa(context.m_decl_context)) { - FindObjCPropertyDecls(context); + FindObjCPropertyAndIvarDecls(context); } else if (!isa(context.m_decl_context)) { @@ -499,6 +500,12 @@ const char *name_unique_cstr = name.GetCString(); + static ConstString id_name("id"); + static ConstString Class_name("Class"); + + if (name == id_name || name == Class_name) + return; + if (name_unique_cstr == NULL) return; @@ -567,16 +574,10 @@ } } - static ConstString id_name("id"); - static ConstString Class_name("Class"); - do { TypeList types; SymbolContext null_sc; - - if (name == id_name || name == Class_name) - break; if (module_sp && namespace_decl) module_sp->FindTypes(null_sc, name, &namespace_decl, true, 1, types); @@ -788,62 +789,308 @@ } } +template class TaggedASTDecl { +public: + TaggedASTDecl() : decl(NULL) { } + TaggedASTDecl(D *_decl) : decl(_decl) { } + bool IsValid() const { return (decl != NULL); } + bool IsInvalid() const { return !IsValid(); } + D *operator->() const { return decl; } + D *decl; +}; + +template class TD, class D1> +TD +DynCast(TD source) +{ + return TD (dyn_cast(source.decl)); +} + +template class DeclFromParser; +template class DeclFromUser; + +template class DeclFromParser : public TaggedASTDecl { +public: + DeclFromParser() : TaggedASTDecl() { } + DeclFromParser(D *_decl) : TaggedASTDecl(_decl) { } + + DeclFromUser GetOrigin(ClangASTImporter *importer); +}; + +template class DeclFromUser : public TaggedASTDecl { +public: + DeclFromUser() : TaggedASTDecl() { } + DeclFromUser(D *_decl) : TaggedASTDecl(_decl) { } + + DeclFromParser Import(ClangASTImporter *importer, ASTContext &dest_ctx); +}; + +template +DeclFromUser +DeclFromParser::GetOrigin(ClangASTImporter *importer) +{ + DeclFromUser <> origin_decl; + importer->ResolveDeclOrigin(this->decl, &origin_decl.decl, NULL); + if (origin_decl.IsInvalid()) + return DeclFromUser(); + return DeclFromUser(dyn_cast(origin_decl.decl)); +} + +template +DeclFromParser +DeclFromUser::Import(ClangASTImporter *importer, ASTContext &dest_ctx) +{ + DeclFromParser <> parser_generic_decl(importer->CopyDecl(&dest_ctx, &this->decl->getASTContext(), this->decl)); + if (parser_generic_decl.IsInvalid()) + return DeclFromParser(); + return DeclFromParser(dyn_cast(parser_generic_decl.decl)); +} + void -ClangASTSource::FindObjCPropertyDecls (NameSearchContext &context) +ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); static unsigned int invocation_id = 0; unsigned int current_id = invocation_id++; - const ObjCInterfaceDecl *iface_decl = cast(context.m_decl_context); - Decl *orig_decl; - ASTContext *orig_ast_ctx; - - m_ast_importer->ResolveDeclOrigin(iface_decl, &orig_decl, &orig_ast_ctx); + DeclFromParser parser_iface_decl(cast(context.m_decl_context)); + DeclFromUser origin_iface_decl(parser_iface_decl.GetOrigin(m_ast_importer)); - if (!orig_decl) + if (origin_iface_decl.IsInvalid()) return; - ObjCInterfaceDecl *orig_iface_decl = dyn_cast(orig_decl); + std::string name_str = context.m_decl_name.getAsString(); + StringRef name(name_str.c_str()); + IdentifierInfo &name_identifier(origin_iface_decl->getASTContext().Idents.get(name)); - if (!orig_iface_decl) - return; + if (log) + log->Printf("ClangASTSource::FindObjCPropertyAndIvarDecls[%d] on (ASTContext*)%p for '%s.%s'", + current_id, + m_ast_context, + parser_iface_decl->getNameAsString().c_str(), + name_str.c_str()); - if (!ClangASTContext::GetCompleteDecl(orig_ast_ctx, orig_iface_decl)) - return; + DeclFromUser origin_property_decl(origin_iface_decl->FindPropertyDeclaration(&name_identifier)); + + if (origin_property_decl.IsValid()) + { + DeclFromParser parser_property_decl(origin_property_decl.Import(m_ast_importer, *m_ast_context)); + if (parser_property_decl.IsValid()) + { + if (log) + { + ASTDumper dumper((Decl*)parser_property_decl.decl); + log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); + } + + context.AddNamedDecl(parser_property_decl.decl); + } + } + + DeclFromUser origin_ivar_decl(origin_iface_decl->getIvarDecl(&name_identifier)); + + if (origin_ivar_decl.IsValid()) + { + DeclFromParser parser_ivar_decl(origin_ivar_decl.Import(m_ast_importer, *m_ast_context)); + if (parser_ivar_decl.IsValid()) + { + if (log) + { + ASTDumper dumper((Decl*)parser_ivar_decl.decl); + log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); + } + + context.AddNamedDecl(parser_ivar_decl.decl); + } + } +} + +typedef llvm::DenseMap FieldOffsetMap; +typedef llvm::DenseMap BaseOffsetMap; + +template +static bool +ImportOffsetMap (llvm::DenseMap &destination_map, + llvm::DenseMap &source_map, + ClangASTImporter *importer, + ASTContext &dest_ctx) +{ + typedef llvm::DenseMap MapType; + + for (typename MapType::iterator fi = source_map.begin(), fe = source_map.end(); + fi != fe; + ++fi) + { + DeclFromUser user_decl(const_cast(fi->first)); + DeclFromParser parser_decl(user_decl.Import(importer, dest_ctx)); + if (parser_decl.IsInvalid()) + return false; + destination_map.insert(std::pair(parser_decl.decl, fi->second)); + } + + return true; +} + +template bool ExtractBaseOffsets (const ASTRecordLayout &record_layout, + DeclFromUser &record, + BaseOffsetMap &base_offsets) +{ + for (CXXRecordDecl::base_class_const_iterator + bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()), + be = (IsVirtual ? record->vbases_end() : record->bases_end()); + bi != be; + ++bi) + { + if (!IsVirtual && bi->isVirtual()) + continue; + + const clang::Type *origin_base_type = bi->getType().getTypePtr(); + const clang::RecordType *origin_base_record_type = origin_base_type->getAs(); + + if (!origin_base_record_type) + return false; + + DeclFromUser origin_base_record(origin_base_record_type->getDecl()); + + if (origin_base_record.IsInvalid()) + return false; + + DeclFromUser origin_base_cxx_record(DynCast(origin_base_record)); + + if (origin_base_cxx_record.IsInvalid()) + return false; + + CharUnits base_offset; + + if (IsVirtual) + base_offset = record_layout.getVBaseClassOffset(origin_base_cxx_record.decl); + else + base_offset = record_layout.getBaseClassOffset(origin_base_cxx_record.decl); + + base_offsets.insert(std::pair(origin_base_cxx_record.decl, base_offset)); + } - std::string property_name_str = context.m_decl_name.getAsString(); - StringRef property_name(property_name_str.c_str()); - ObjCPropertyDecl *property_decl = orig_iface_decl->FindPropertyDeclaration(&orig_ast_ctx->Idents.get(property_name)); + return true; +} + +bool +ClangASTSource::layoutRecordType(const RecordDecl *record, + uint64_t &size, + uint64_t &alignment, + FieldOffsetMap &field_offsets, + BaseOffsetMap &base_offsets, + BaseOffsetMap &virtual_base_offsets) +{ + static unsigned int invocation_id = 0; + unsigned int current_id = invocation_id++; + + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + if (!record->getNameAsString().compare("PseudoObjectExprBitfields")) + fprintf(stderr, "THIS IS THE ONE!"); if (log) - log->Printf("ClangASTSource::FindObjCPropertyDecls[%d] on (ASTContext*)%p for property '%s.%s'", - current_id, + { + log->Printf("LayoutRecordType[%u] on (RecordDecl*)%p [name = '%s']", + current_id, m_ast_context, - iface_decl->getNameAsString().c_str(), - property_name_str.c_str()); + record->getNameAsString().c_str()); + } - if (!property_decl) - return; - Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, orig_ast_ctx, property_decl); + DeclFromParser parser_record(record); + DeclFromUser origin_record(parser_record.GetOrigin(m_ast_importer)); - if (!copied_decl) - return; + if (origin_record.IsInvalid()) + return false; + + FieldOffsetMap origin_field_offsets; + BaseOffsetMap origin_base_offsets; + BaseOffsetMap origin_virtual_base_offsets; - ObjCPropertyDecl *copied_property_decl = dyn_cast(copied_decl); + const ASTRecordLayout &record_layout(origin_record->getASTContext().getASTRecordLayout(origin_record.decl)); - if (!copied_property_decl) - return; + int field_idx = 0; + + for (RecordDecl::field_iterator fi = origin_record->field_begin(), fe = origin_record->field_end(); + fi != fe; + ++fi) + { + uint64_t field_offset = record_layout.getFieldOffset(field_idx); + + origin_field_offsets.insert(std::pair(*fi, field_offset)); + + field_idx++; + } + + ASTContext &parser_ast_context(record->getASTContext()); + + DeclFromUser origin_cxx_record(DynCast(origin_record)); + + if (origin_cxx_record.IsValid()) + { + if (!ExtractBaseOffsets(record_layout, origin_cxx_record, origin_base_offsets) || + !ExtractBaseOffsets(record_layout, origin_cxx_record, origin_virtual_base_offsets)) + return false; + } + + if (!ImportOffsetMap(field_offsets, origin_field_offsets, m_ast_importer, parser_ast_context) || + !ImportOffsetMap(base_offsets, origin_base_offsets, m_ast_importer, parser_ast_context) || + !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets, m_ast_importer, parser_ast_context)) + return false; + + size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth(); + alignment = record_layout.getAlignment().getQuantity() * m_ast_context->getCharWidth(); if (log) { - ASTDumper dumper((Decl*)copied_property_decl); - log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); + log->Printf("LRT[%u] returned:", current_id); + log->Printf("LRT[%u] Original = (RecordDecl*)%p", current_id, origin_record.decl); + log->Printf("LRT[%u] Size = %lld", current_id, size); + log->Printf("LRT[%u] Alignment = %lld", current_id, alignment); + log->Printf("LRT[%u] Fields:", current_id); + for (RecordDecl::field_iterator fi = record->field_begin(), fe = record->field_end(); + fi != fe; + ++fi) + { + log->Printf("LRT[%u] (FieldDecl*)%p, Name = '%s', Offset = %lld bits", + current_id, + *fi, + fi->getNameAsString().c_str(), + field_offsets[*fi]); + } + DeclFromParser parser_cxx_record = DynCast(parser_record); + if (parser_cxx_record.IsValid()) + { + log->Printf("LRT[%u] Bases:", current_id); + for (CXXRecordDecl::base_class_const_iterator bi = parser_cxx_record->bases_begin(), be = parser_cxx_record->bases_end(); + bi != be; + ++bi) + { + bool is_virtual = bi->isVirtual(); + + QualType base_type = bi->getType(); + const RecordType *base_record_type = base_type->getAs(); + DeclFromParser base_record(base_record_type->getDecl()); + DeclFromParser base_cxx_record = DynCast(base_record); + + log->Printf("LRT[%u] %s(CXXRecordDecl*)%p, Name = '%s', Offset = %lld chars", + current_id, + (is_virtual ? "Virtual " : ""), + base_cxx_record.decl, + base_cxx_record.decl->getNameAsString().c_str(), + (is_virtual ? virtual_base_offsets[base_cxx_record.decl].getQuantity() : + base_offsets[base_cxx_record.decl].getQuantity())); + } + } + else + { + log->Printf("LRD[%u] Not a CXXRecord, so no bases", current_id); + } } - - context.AddNamedDecl(copied_property_decl); + + return true; } void Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Sat Feb 4 02:49:35 2012 @@ -415,7 +415,8 @@ const size_t pvar_byte_size = pvar_sp->GetByteSize(); uint8_t *pvar_data = pvar_sp->GetValueBytes(); - ReadTarget(pvar_data, value, pvar_byte_size); + if (!ReadTarget(pvar_data, value, pvar_byte_size)) + return false; pvar_sp->m_flags &= ~(ClangExpressionVariable::EVNeedsFreezeDry); } @@ -425,6 +426,16 @@ return true; } +void +ClangExpressionDeclMap::RemoveResultVariable +( + const ConstString &name +) +{ + ClangExpressionVariableSP pvar_sp = m_parser_vars->m_persistent_vars->GetVariable(name); + m_parser_vars->m_persistent_vars->RemovePersistentVariable(pvar_sp); +} + bool ClangExpressionDeclMap::AddPersistentVariable ( @@ -2322,6 +2333,12 @@ if (name_unique_cstr == NULL) return; + static ConstString id_name("id"); + static ConstString Class_name("Class"); + + if (name == id_name || name == Class_name) + return; + // Only look for functions by name out in our symbols if the function // doesn't start with our phony prefix of '$' Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr(); Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Sat Feb 4 02:49:35 2012 @@ -172,8 +172,7 @@ // If there are any AST files to merge, create a frontend action // adaptor to perform the merge. if (!CI.getFrontendOpts().ASTMergeFiles.empty()) - Act = new ASTMergeAction(Act, &CI.getFrontendOpts().ASTMergeFiles[0], - CI.getFrontendOpts().ASTMergeFiles.size()); + Act = new ASTMergeAction(Act, CI.getFrontendOpts().ASTMergeFiles); return Act; } @@ -492,12 +491,7 @@ error_stream, function_name.c_str()); - if (!ir_for_target.runOnModule(*module)) - { - err.SetErrorToGenericError(); - err.SetErrorString("Couldn't prepare the expression for execution in the target"); - return err; - } + ir_for_target.runOnModule(*module); Error &interpreter_error(ir_for_target.getInterpreterError()); @@ -519,6 +513,7 @@ err.SetErrorString("Execution needed to run in the target, but the target can't be run"); else err.SetErrorStringWithFormat("Interpreting the expression locally failed: %s", interpreter_error.AsCString()); + return err; } @@ -629,58 +624,9 @@ err.SetErrorString("Couldn't write the JIT compiled code into the target because there is no target"); return err; } - - // Look over the regions allocated for the function compiled. The JIT - // tries to allocate the functions & stubs close together, so we should try to - // write them that way too... - // For now I only write functions with no stubs, globals, exception tables, - // etc. So I only need to write the functions. - - size_t alloc_size = 0; - - std::map::iterator fun_pos = jit_memory_manager->m_functions.begin(); - std::map::iterator fun_end = jit_memory_manager->m_functions.end(); - - for (; fun_pos != fun_end; ++fun_pos) - { - size_t mem_size = fun_pos->second - fun_pos->first; - if (log) - log->Printf ("JIT memory: [%p - %p) size = %zu", fun_pos->first, fun_pos->second, mem_size); - alloc_size += mem_size; - } - - Error alloc_error; - func_allocation_addr = process->AllocateMemory (alloc_size, - lldb::ePermissionsReadable|lldb::ePermissionsExecutable, - alloc_error); - - if (func_allocation_addr == LLDB_INVALID_ADDRESS) - { - err.SetErrorToGenericError(); - err.SetErrorStringWithFormat("Couldn't allocate memory for the JITted function: %s", alloc_error.AsCString("unknown error")); - return err; - } - - lldb::addr_t cursor = func_allocation_addr; - - for (fun_pos = jit_memory_manager->m_functions.begin(); fun_pos != fun_end; fun_pos++) - { - lldb::addr_t lstart = (lldb::addr_t) (*fun_pos).first; - lldb::addr_t lend = (lldb::addr_t) (*fun_pos).second; - size_t size = lend - lstart; - Error write_error; - - if (process->WriteMemory(cursor, (void *) lstart, size, write_error) != size) - { - err.SetErrorToGenericError(); - err.SetErrorStringWithFormat("Couldn't copy JIT code for function into the target: %s", write_error.AsCString("unknown error")); - return err; - } - - jit_memory_manager->AddToLocalToRemoteMap (lstart, size, cursor); - cursor += size; - } + jit_memory_manager->CommitAllocations(*process); + jit_memory_manager->WriteData(*process); std::vector::iterator pos, end = m_jitted_functions.end(); @@ -690,7 +636,8 @@ if (!(*pos).m_name.compare(function_name.c_str())) { - func_end = jit_memory_manager->GetRemoteRangeForLocal ((*pos).m_local_addr).second; + RecordingMemoryManager::AddrRange func_range = jit_memory_manager->GetRemoteRangeForLocal((*pos).m_local_addr); + func_end = func_range.first + func_range.second; func_addr = (*pos).m_remote_addr; } } @@ -766,7 +713,7 @@ } if (log) - log->Printf("Function's code range is [0x%llx-0x%llx]", func_range.first, func_range.second); + log->Printf("Function's code range is [0x%llx+0x%llx]", func_range.first, func_range.second); Target *target = exe_ctx.GetTargetPtr(); if (!target) @@ -775,7 +722,7 @@ ret.SetErrorString("Couldn't find the target"); } - lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second - func_remote_addr, 0)); + lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second, 0)); Process *process = exe_ctx.GetProcessPtr(); Error err; Modified: lldb/trunk/source/Expression/ClangPersistentVariables.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangPersistentVariables.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangPersistentVariables.cpp (original) +++ lldb/trunk/source/Expression/ClangPersistentVariables.cpp Sat Feb 4 02:49:35 2012 @@ -46,6 +46,20 @@ return var_sp; } +void +ClangPersistentVariables::RemovePersistentVariable (lldb::ClangExpressionVariableSP variable) +{ + RemoveVariable(variable); + + const char *name = variable->GetName().AsCString(); + + if (*name != '$') + return; + name++; + + if (strtoul(name, NULL, 0) == m_next_persistent_variable_id - 1) + m_next_persistent_variable_id--; +} ConstString ClangPersistentVariables::GetNextPersistentVariableName () Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Sat Feb 4 02:49:35 2012 @@ -2669,6 +2669,11 @@ return true; } + if (m_execution_policy == lldb_private::eExecutionPolicyNever) { + m_decl_map->RemoveResultVariable(m_result_name); + return false; + } + if (log && log->GetVerbose()) { std::string s; Modified: lldb/trunk/source/Expression/IRInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRInterpreter.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRInterpreter.cpp (original) +++ lldb/trunk/source/Expression/IRInterpreter.cpp Sat Feb 4 02:49:35 2012 @@ -873,6 +873,7 @@ static const char *memory_write_error = "Interpreter couldn't write to memory"; static const char *memory_read_error = "Interpreter couldn't read from memory"; static const char *infinite_loop_error = "Interpreter ran for too many cycles"; +static const char *bad_result_error = "Result of expression is in bad memory"; bool IRInterpreter::supportsFunction (Function &llvm_function, @@ -1524,7 +1525,17 @@ return true; GlobalValue *result_value = llvm_module.getNamedValue(result_name.GetCString()); - return frame.ConstructResult(result, result_value, result_name, result_type, llvm_module); + + if (!frame.ConstructResult(result, result_value, result_name, result_type, llvm_module)) + { + if (log) + log->Printf("Couldn't construct the expression's result"); + err.SetErrorToGenericError(); + err.SetErrorString(bad_result_error); + return false; + } + + return true; } case Instruction::Store: { Modified: lldb/trunk/source/Expression/RecordingMemoryManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/RecordingMemoryManager.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Expression/RecordingMemoryManager.cpp (original) +++ lldb/trunk/source/Expression/RecordingMemoryManager.cpp Sat Feb 4 02:49:35 2012 @@ -43,8 +43,7 @@ RecordingMemoryManager::startFunctionBody(const llvm::Function *F, uintptr_t &ActualSize) { - uint8_t *return_value = m_default_mm_ap->startFunctionBody(F, ActualSize); - return return_value; + return m_default_mm_ap->startFunctionBody(F, ActualSize); } uint8_t * @@ -52,7 +51,21 @@ unsigned Alignment) { uint8_t *return_value = m_default_mm_ap->allocateStub(F, StubSize, Alignment); - m_stubs.insert (std::pair(return_value, StubSize)); + + Allocation allocation; + allocation.m_size = StubSize; + allocation.m_alignment = Alignment; + allocation.m_local_start = (uintptr_t)return_value; + + if (m_log) + { + m_log->Printf("RecordingMemoryManager::allocateStub (F=%p, StubSize=%u, Alignment=%u) = %p", + F, StubSize, Alignment, return_value); + allocation.dump(m_log); + } + + m_allocations.push_back(allocation); + return return_value; } @@ -61,31 +74,96 @@ uint8_t *FunctionEnd) { m_default_mm_ap->endFunctionBody(F, FunctionStart, FunctionEnd); - if (m_log) - m_log->Printf("Adding [%p-%p] to m_functions", - FunctionStart, FunctionEnd); - m_functions.insert(std::pair(FunctionStart, FunctionEnd)); } uint8_t * RecordingMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment) { uint8_t *return_value = m_default_mm_ap->allocateSpace(Size, Alignment); + + Allocation allocation; + allocation.m_size = Size; + allocation.m_alignment = Alignment; + allocation.m_local_start = (uintptr_t)return_value; + if (m_log) - m_log->Printf("RecordingMemoryManager::allocateSpace(Size=0x%llx, Alignment=%u) = %p", + { + m_log->Printf("RecordingMemoryManager::allocateSpace(Size=%llu, Alignment=%u) = %p", (uint64_t)Size, Alignment, return_value); - m_spaceBlocks.insert (std::pair(return_value, Size)); + allocation.dump(m_log); + } + + m_allocations.push_back(allocation); + + return return_value; +} + +uint8_t * +RecordingMemoryManager::allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) +{ + uint8_t *return_value = m_default_mm_ap->allocateCodeSection(Size, Alignment, SectionID); + + Allocation allocation; + allocation.m_size = Size; + allocation.m_alignment = Alignment; + allocation.m_local_start = (uintptr_t)return_value; + allocation.m_section_id = SectionID; + allocation.m_executable = true; + + if (m_log) + { + m_log->Printf("RecordingMemoryManager::allocateCodeSection(Size=0x%llx, Alignment=%u, SectionID=%u) = %p", + (uint64_t)Size, Alignment, SectionID, return_value); + allocation.dump(m_log); + } + + m_allocations.push_back(allocation); + return return_value; } uint8_t * +RecordingMemoryManager::allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) +{ + uint8_t *return_value = m_default_mm_ap->allocateDataSection(Size, Alignment, SectionID); + + Allocation allocation; + allocation.m_size = Size; + allocation.m_alignment = Alignment; + allocation.m_local_start = (uintptr_t)return_value; + allocation.m_section_id = SectionID; + + if (m_log) + { + m_log->Printf("RecordingMemoryManager::allocateDataSection(Size=0x%llx, Alignment=%u, SectionID=%u) = %p", + (uint64_t)Size, Alignment, SectionID, return_value); + allocation.dump(m_log); + } + + m_allocations.push_back(allocation); + + return return_value; +} + +uint8_t * RecordingMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment) { uint8_t *return_value = m_default_mm_ap->allocateGlobal(Size, Alignment); + + Allocation allocation; + allocation.m_size = Size; + allocation.m_alignment = Alignment; + allocation.m_local_start = (uintptr_t)return_value; + if (m_log) + { m_log->Printf("RecordingMemoryManager::allocateGlobal(Size=0x%llx, Alignment=%u) = %p", (uint64_t)Size, Alignment, return_value); - m_globals.insert (std::pair(return_value, Size)); + allocation.dump(m_log); + } + + m_allocations.push_back(allocation); + return return_value; } @@ -99,8 +177,7 @@ RecordingMemoryManager::startExceptionTable(const llvm::Function* F, uintptr_t &ActualSize) { - uint8_t *return_value = m_default_mm_ap->startExceptionTable(F, ActualSize); - return return_value; + return m_default_mm_ap->startExceptionTable(F, ActualSize); } void @@ -108,7 +185,6 @@ uint8_t *TableEnd, uint8_t* FrameRegister) { m_default_mm_ap->endExceptionTable(F, TableStart, TableEnd, FrameRegister); - m_exception_tables.insert (std::pair(TableStart, TableEnd)); } void @@ -120,43 +196,125 @@ lldb::addr_t RecordingMemoryManager::GetRemoteAddressForLocal (lldb::addr_t local_address) { - std::vector::iterator pos, end = m_address_map.end(); - for (pos = m_address_map.begin(); pos < end; pos++) + for (AllocationList::iterator ai = m_allocations.begin(), ae = m_allocations.end(); + ai != ae; + ++ai) { - lldb::addr_t lstart = (*pos).m_local_start; - if (local_address >= lstart && local_address < lstart + (*pos).m_size) - { - return (*pos).m_remote_start + (local_address - lstart); - } + if (local_address >= ai->m_local_start && + local_address < ai->m_local_start + ai->m_size) + return ai->m_remote_start + (local_address - ai->m_local_start); } + return LLDB_INVALID_ADDRESS; } -std::pair +RecordingMemoryManager::AddrRange RecordingMemoryManager::GetRemoteRangeForLocal (lldb::addr_t local_address) { - std::vector::iterator pos, end = m_address_map.end(); + for (AllocationList::iterator ai = m_allocations.begin(), ae = m_allocations.end(); + ai != ae; + ++ai) + { + if (local_address >= ai->m_local_start && + local_address < ai->m_local_start + ai->m_size) + return AddrRange(ai->m_remote_start, ai->m_size); + } + + return AddrRange (0, 0); +} + +bool +RecordingMemoryManager::CommitAllocations (Process &process) +{ + bool ret = true; + + for (AllocationList::iterator ai = m_allocations.begin(), ae = m_allocations.end(); + ai != ae; + ++ai) + { + if (ai->m_allocated) + continue; + + lldb_private::Error err; + + ai->m_remote_allocation = process.AllocateMemory( + ai->m_size + ai->m_alignment - 1, + ai->m_executable ? (lldb::ePermissionsReadable | lldb::ePermissionsExecutable) + : (lldb::ePermissionsReadable | lldb::ePermissionsWritable), + err); + + uint64_t mask = ai->m_alignment - 1; + + ai->m_remote_start = (ai->m_remote_allocation + mask) & (~mask); + + if (!err.Success()) + { + ret = false; + break; + } + + ai->m_allocated = true; + + if (m_log) + { + m_log->Printf("RecordingMemoryManager::CommitAllocations() committed an allocation"); + ai->dump(m_log); + } + } + + if (!ret) + { + for (AllocationList::iterator ai = m_allocations.end(), ae = m_allocations.end(); + ai != ae; + ++ai) + { + if (ai->m_allocated) + process.DeallocateMemory(ai->m_remote_start); + } + } - for (pos = m_address_map.begin(); pos < end; ++pos) + return ret; +} + +bool +RecordingMemoryManager::WriteData (Process &process) +{ + for (AllocationList::iterator ai = m_allocations.begin(), ae = m_allocations.end(); + ai != ae; + ++ai) { - lldb::addr_t lstart = pos->m_local_start; - lldb::addr_t lend = lstart + pos->m_size; + if (!ai->m_allocated) + return false; - if (local_address >= lstart && local_address < lend) + lldb_private::Error err; + + if (process.WriteMemory(ai->m_remote_start, + (void*)ai->m_local_start, + ai->m_size, + err) != ai->m_size || + !err.Success()) + return false; + + if (m_log) { - return std::pair (pos->m_remote_start, pos->m_remote_start + pos->m_size); + m_log->Printf("RecordingMemoryManager::CommitAllocations() wrote an allocation"); + ai->dump(m_log); } } - return std::pair (0, 0); + return true; } -void -RecordingMemoryManager::AddToLocalToRemoteMap (lldb::addr_t lstart, size_t size, lldb::addr_t rstart) +void +RecordingMemoryManager::Allocation::dump (lldb::LogSP log) { - if (m_log) - m_log->Printf("Adding local [0x%llx-0x%llx], remote [0x%llx-0x%llx] to local->remote map", lstart, lstart + size, rstart, rstart + size); + if (!log) + return; - m_address_map.push_back (LocalToRemoteAddressRange(lstart, size, rstart)); + log->Printf("[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d)", + (unsigned long long)m_local_start, + (unsigned long long)m_size, + (unsigned long long)m_remote_start, + (unsigned)m_alignment, + (unsigned)m_section_id); } - Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sat Feb 4 02:49:35 2012 @@ -79,9 +79,20 @@ using namespace lldb_private; static inline bool -DW_TAG_is_function_tag (dw_tag_t tag) +child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) { - return tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine; + switch (tag) + { + default: + break; + case DW_TAG_subprogram: + case DW_TAG_inlined_subroutine: + case DW_TAG_class_type: + case DW_TAG_structure_type: + case DW_TAG_union_type: + return true; + } + return false; } static AccessType @@ -1475,10 +1486,41 @@ encoding_uid); } - if (member_byte_offset != UINT32_MAX) + if (member_byte_offset != UINT32_MAX || bit_size != 0) { - // Set the field offset in bits - layout_info.field_offsets.insert(std::make_pair(field_decl, member_byte_offset * 8)); + ///////////////////////////////////////////////////////////// + // How to locate a field given the DWARF debug information + // + // AT_byte_size indicates the size of the word in which the + // bit offset must be interpreted. + // + // AT_data_member_location indicates the byte offset of the + // word from the base address of the structure. + // + // AT_bit_offset indicates how many bits into the word + // (according to the host endianness) the low-order bit of + // the field starts. AT_bit_offset can be negative. + // + // AT_bit_size indicates the size of the field in bits. + ///////////////////////////////////////////////////////////// + + ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian(); + + uint64_t total_bit_offset = 0; + + total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); + + if (object_endian == eByteOrderLittle) + { + total_bit_offset += byte_size * 8; + total_bit_offset -= (bit_offset + bit_size); + } + else + { + total_bit_offset += bit_offset; + } + + layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset)); } if (prop_name != NULL) { @@ -1646,7 +1688,7 @@ Type* SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) -{ +{ if (die != NULL) { LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); @@ -1677,7 +1719,7 @@ decl_ctx_die->GetOffset()); Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); - if (DW_TAG_is_function_tag(die->Tag())) + if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) { if (log) GetObjectFile()->GetModule()->LogMessage (log.get(), @@ -1907,8 +1949,7 @@ } } -#if 0 - // Disable assisted layout until we get the clang side hooked up + if (!layout_info.field_offsets.empty()) { if (type) @@ -1944,7 +1985,6 @@ m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); } } -#endif } ast.CompleteTagDeclarationDefinition (clang_type); return clang_type; @@ -4053,7 +4093,7 @@ DWARFDIECollection decl_ctx_1; DWARFDIECollection decl_ctx_2; die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); - die1->GetDeclContextDIEs (this, cu2, decl_ctx_2); + die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); const size_t count1 = decl_ctx_1.Size(); const size_t count2 = decl_ctx_2.Size(); if (count1 != count2) @@ -4079,7 +4119,7 @@ decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); const char *name1 = decl_ctx_die1->GetName(this, cu1); - const char *name2 = decl_ctx_die1->GetName(this, cu2); + const char *name2 = decl_ctx_die2->GetName(this, cu2); // If the string was from a DW_FORM_strp, then the pointer will often // be the same! if (name1 != name2) @@ -4231,16 +4271,40 @@ if (type_is_new_ptr) *type_is_new_ptr = false; + + static int depth = -1; + + class DepthTaker { + public: + DepthTaker (int &depth) : m_depth(depth) { ++m_depth; } + ~DepthTaker () { --m_depth; } + int &m_depth; + } depth_taker(depth); AccessType accessibility = eAccessNone; if (die != NULL) { LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); if (log) - GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s'", - die->GetOffset(), + { + const DWARFDebugInfoEntry *context_die; + clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); + + std::string name_storage; + + const char* qual_name = die->GetQualifiedName(this, + dwarf_cu, + name_storage); + + GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (depth = %d, die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s '%s'='%s')", + depth, + die->GetOffset(), + context, + context_die->GetOffset(), DW_TAG_value_to_name(die->Tag()), - die->GetName(this, dwarf_cu)); + die->GetName(this, dwarf_cu), + qual_name); + } // // LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); // if (log && dwarf_cu) @@ -5010,6 +5074,9 @@ if (type_name_cstr) { + if (die->GetOffset() == 0xaeaba) + fprintf(stderr, "This is the one!"); + bool type_handled = false; if (tag == DW_TAG_subprogram) { Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Sat Feb 4 02:49:35 2012 @@ -82,6 +82,15 @@ const clang::Type::TypeClass type_class = qual_type->getTypeClass(); switch (type_class) { + case clang::Type::ConstantArray: + { + const clang::ArrayType *array_type = dyn_cast(qual_type.getTypePtr()); + + if (array_type) + return GetCompleteQualType (ast, array_type->getElementType()); + } + break; + case clang::Type::Record: case clang::Type::Enum: { @@ -124,8 +133,10 @@ // because it only supports TagDecl objects right now... if (class_interface_decl) { - bool is_forward_decl = class_interface_decl->isForwardDecl(); - if (is_forward_decl && class_interface_decl->hasExternalLexicalStorage()) + if (class_interface_decl->getDefinition()) + return true; + + if (class_interface_decl->hasExternalLexicalStorage()) { if (ast) { @@ -133,15 +144,12 @@ if (external_ast_source) { external_ast_source->CompleteType (class_interface_decl); - is_forward_decl = class_interface_decl->isForwardDecl(); + return !objc_class_type->isIncompleteType(); } } - return is_forward_decl == false; } - return true; - } - else return false; + } } } break; @@ -568,7 +576,7 @@ { if (m_log) { - llvm::SmallVectorImpl diag_str(10); + llvm::SmallVector diag_str(10); info.FormatDiagnostic(diag_str); diag_str.push_back('\0'); m_log->Printf("Compiler diagnostic: %s\n", diag_str.data()); @@ -1231,6 +1239,10 @@ { if (access_type != eAccessNone) class_template_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); + + //if (TagDecl *ctx_tag_decl = dyn_cast(decl_ctx)) + // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); + decl_ctx->addDecl (class_template_decl); #ifdef LLDB_CONFIGURATION_DEBUG @@ -1575,6 +1587,18 @@ bool ClangASTContext::CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, uint32_t num_params) { + switch (op_kind) + { + default: + break; + // C++ standard allows any number of arguments to new/delete + case OO_New: + case OO_Array_New: + case OO_Delete: + case OO_Array_Delete: + return true; + } + #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) case OO_##Name: return check_op_param (op_kind, Unary, Binary, num_params); switch (op_kind) { @@ -2033,8 +2057,9 @@ decl_ctx, SourceLocation(), &ast->Idents.get(name), + NULL, SourceLocation(), - isForwardDecl, + /*isForwardDecl,*/ isInternal); return ast->getObjCInterfaceType(decl).getAsOpaquePtr(); @@ -3759,7 +3784,7 @@ } // We have a pointer to an simple type - if (idx == 0) + if (idx == 0 && GetCompleteQualType(ast, pointee_type)) { std::pair clang_type_info = ast->getTypeInfo(pointee_type); assert(clang_type_info.first % 8 == 0); @@ -4706,7 +4731,13 @@ return namespace_decl; } - namespace_decl = NamespaceDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(), &identifier_info); + namespace_decl = NamespaceDecl::Create(*ast, + decl_ctx, + false, + SourceLocation(), + SourceLocation(), + &identifier_info, + NULL); decl_ctx->addDecl (namespace_decl); } @@ -4718,7 +4749,13 @@ if (namespace_decl) return namespace_decl; - namespace_decl = NamespaceDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(), NULL); + namespace_decl = NamespaceDecl::Create(*ast, + decl_ctx, + false, + SourceLocation(), + SourceLocation(), + NULL, + NULL); translation_unit_decl->setAnonymousNamespace (namespace_decl); translation_unit_decl->addDecl (namespace_decl); assert (namespace_decl == translation_unit_decl->getAnonymousNamespace()); @@ -4731,7 +4768,13 @@ namespace_decl = parent_namespace_decl->getAnonymousNamespace(); if (namespace_decl) return namespace_decl; - namespace_decl = NamespaceDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(), NULL); + namespace_decl = NamespaceDecl::Create(*ast, + decl_ctx, + false, + SourceLocation(), + SourceLocation(), + NULL, + NULL); parent_namespace_decl->setAnonymousNamespace (namespace_decl); parent_namespace_decl->addDecl (namespace_decl); assert (namespace_decl == parent_namespace_decl->getAnonymousNamespace()); @@ -4906,6 +4949,17 @@ return true; } } + + const ObjCObjectType *object_type = dyn_cast(t); + if (object_type) + { + ObjCInterfaceDecl *interface_decl = object_type->getInterface(); + if (interface_decl) + { + interface_decl->startDefinition(); + return true; + } + } } } return false; @@ -4931,9 +4985,8 @@ if (objc_class_type) { - ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); - - class_interface_decl->completedForwardDecl(); + // ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); + // class_interface_decl->completeDefinition(); } const EnumType *enum_type = dyn_cast(qual_type.getTypePtr()); @@ -6064,7 +6117,7 @@ } else if (clang::ObjCInterfaceDecl *objc_interface_decl = llvm::dyn_cast(decl)) { - if (!objc_interface_decl->isForwardDecl()) + if (objc_interface_decl->getDefinition()) return true; if (!objc_interface_decl->hasExternalLexicalStorage()) @@ -6072,7 +6125,7 @@ ast_source->CompleteType(objc_interface_decl); - return !objc_interface_decl->isForwardDecl(); + return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); } else { Modified: lldb/trunk/source/Symbol/ClangASTImporter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTImporter.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTImporter.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTImporter.cpp Sat Feb 4 02:49:35 2012 @@ -137,6 +137,43 @@ return result; } +void +ClangASTImporter::CompleteDecl (clang::Decl *decl) +{ + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + if (log) + log->Printf(" [ClangASTImporter] CompleteDecl called on (%sDecl*)%p", + decl->getDeclKindName(), + decl); + + if (ObjCInterfaceDecl *interface_decl = dyn_cast(decl)) + { + if (!interface_decl->getDefinition()) + { + interface_decl->startDefinition(); + CompleteObjCInterfaceDecl(interface_decl); + } + } + else if (ObjCProtocolDecl *protocol_decl = dyn_cast(protocol_decl)) + { + if (!protocol_decl->getDefinition()) + protocol_decl->startDefinition(); + } + else if (TagDecl *tag_decl = dyn_cast(decl)) + { + if (!tag_decl->getDefinition() && !tag_decl->isBeingDefined()) + { + tag_decl->startDefinition(); + CompleteTagDecl(tag_decl); + tag_decl->setCompleteDefinition(true); + } + } + else { + assert (0 && "CompleteDecl called on a Decl that can't be completed"); + } +} + bool ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl) { @@ -310,14 +347,26 @@ ClangASTImporter::Minion::ImportDefinitionTo (clang::Decl *to, clang::Decl *from) { ASTImporter::Imported(from, to); + + ObjCInterfaceDecl *to_objc_interface = dyn_cast(to); + + /* + if (to_objc_interface) + to_objc_interface->startDefinition(); + + CXXRecordDecl *to_cxx_record = dyn_cast(to); + if (to_cxx_record) + to_cxx_record->startDefinition(); + */ + ImportDefinition(from); - + // If we're dealing with an Objective-C class, ensure that the inheritance has // been set up correctly. The ASTImporter may not do this correctly if the // class was originally sourced from symbols. - if (ObjCInterfaceDecl *to_objc_interface = dyn_cast(to)) + if (to_objc_interface) { do { @@ -346,6 +395,9 @@ if (!imported_from_superclass) break; + if (!to_objc_interface->hasDefinition()) + to_objc_interface->startDefinition(); + to_objc_interface->setSuperClass(imported_from_superclass); } while (0); @@ -366,6 +418,10 @@ to, from_named_decl->getName().str().c_str(), from); + + if (!strcmp(from->getDeclKindName(), "ClassTemplateSpecialization") && + !from_named_decl->getName().str().compare("rebind")) + fprintf(stderr, "This is the one!"); } else { @@ -464,17 +520,14 @@ to_interface_decl->setHasExternalLexicalStorage(); to_interface_decl->setHasExternalVisibleStorage(); - - if (to_interface_decl->isForwardDecl()) - to_interface_decl->completedForwardDecl(); - - to_interface_decl->setExternallyCompleted(); + + /*to_interface_decl->setExternallyCompleted();*/ if (log) log->Printf(" [ClangASTImporter] To is an ObjCInterfaceDecl - attributes %s%s%s", (to_interface_decl->hasExternalLexicalStorage() ? " Lexical" : ""), (to_interface_decl->hasExternalVisibleStorage() ? " Visible" : ""), - (to_interface_decl->isForwardDecl() ? " Forward" : "")); + (to_interface_decl->hasDefinition() ? " HasDefinition" : "")); } return clang::ASTImporter::Imported(from, to); Modified: lldb/trunk/source/Symbol/ClangASTType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTType.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTType.cpp Sat Feb 4 02:49:35 2012 @@ -1232,8 +1232,9 @@ if (objc_class_type) { clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); - if (class_interface_decl->isForwardDecl()) - return false; + if (class_interface_decl) + return class_interface_decl->getDefinition() != NULL; + return false; } } return true; @@ -1667,8 +1668,12 @@ // context (which Module it came from) return false; } + + if (!ClangASTContext::GetCompleteType(ast_context, clang_type)) + return false; + clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type)); - + const uint32_t byte_size = (ast_context->getTypeSize (qual_type) + 7) / 8; if (data.GetByteSize() < byte_size) { Modified: lldb/trunk/source/Symbol/ClangExternalASTSourceCallbacks.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangExternalASTSourceCallbacks.cpp?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangExternalASTSourceCallbacks.cpp (original) +++ lldb/trunk/source/Symbol/ClangExternalASTSourceCallbacks.cpp Sat Feb 4 02:49:35 2012 @@ -134,3 +134,24 @@ if (m_callback_objc_decl) m_callback_objc_decl (m_callback_baton, objc_decl); } + +bool +ClangExternalASTSourceCallbacks::layoutRecordType(const clang::RecordDecl *Record, + uint64_t &Size, + uint64_t &Alignment, + llvm::DenseMap &FieldOffsets, + llvm::DenseMap &BaseOffsets, + llvm::DenseMap &VirtualBaseOffsets) +{ + if (m_callback_layout_record_type) + return m_callback_layout_record_type(m_callback_baton, + Record, + Size, + Alignment, + FieldOffsets, + BaseOffsets, + VirtualBaseOffsets); + + return false; +} + Modified: lldb/trunk/test/lang/c/bitfields/TestBitfields.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/bitfields/TestBitfields.py?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/test/lang/c/bitfields/TestBitfields.py (original) +++ lldb/trunk/test/lang/c/bitfields/TestBitfields.py Sat Feb 4 02:49:35 2012 @@ -66,7 +66,7 @@ substrs = ['(uint32_t:1) b1 = 1', '(uint32_t:2) b2 = 3', '(uint32_t:3) b3 = 7', - '(uint32_t:4) b4 = 15', + '(uint32_t) b4 = 15', '(uint32_t:5) b5 = 31', '(uint32_t:6) b6 = 63', '(uint32_t:7) b7 = 127', @@ -78,7 +78,7 @@ substrs = ['(uint32_t:1) b1 = 1', '(uint32_t:2) b2 = 3', '(uint32_t:3) b3 = 7', - '(uint32_t:4) b4 = 15', + '(uint32_t) b4 = 15', '(uint32_t:5) b5 = 31', '(uint32_t:6) b6 = 63', '(uint32_t:7) b7 = 127', @@ -113,8 +113,8 @@ self.DebugSBValue(bits) self.assertTrue(bits.GetTypeName() == "Bits" and bits.GetNumChildren() == 8 and - bits.GetByteSize() == 4, - "(Bits)bits with byte size of 4 and 8 children") + bits.GetByteSize() == 32, + "(Bits)bits with byte size of 32 and 8 children") # Notice the pattern of int(b1.GetValue(), 0). We pass a base of 0 # so that the proper radix is determined based on the contents of the Modified: lldb/trunk/test/lang/c/bitfields/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/bitfields/main.c?rev=149775&r1=149774&r2=149775&view=diff ============================================================================== --- lldb/trunk/test/lang/c/bitfields/main.c (original) +++ lldb/trunk/test/lang/c/bitfields/main.c Sat Feb 4 02:49:35 2012 @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// #include +#include int main (int argc, char const *argv[]) { struct Bits @@ -14,13 +15,15 @@ uint32_t b1 : 1, b2 : 2, b3 : 3, - b4 : 4, + b4 __attribute__ ((align(16))), b5 : 5, b6 : 6, b7 : 7, four : 4; }; + printf("%lu", sizeof(struct Bits)); + struct Bits bits; int i; for (i=0; i<(1<<1); i++) From gclayton at apple.com Sat Feb 4 20:38:54 2012 From: gclayton at apple.com (Greg Clayton) Date: Sun, 05 Feb 2012 02:38:54 -0000 Subject: [Lldb-commits] [lldb] r149804 - in /lldb/trunk: include/lldb/ include/lldb/API/ include/lldb/Core/ include/lldb/Symbol/ include/lldb/Target/ scripts/Python/interface/ source/API/ source/Commands/ source/Core/ source/Plugins/DynamicLoader/MacOSX-DYLD/ source/Plugins/ObjectFile/ELF/ source/Plugins/ObjectFile/Mach-O/ source/Plugins/ObjectFile/PECOFF/ source/Plugins/SymbolFile/DWARF/ source/Symbol/ source/Target/ Message-ID: <20120205023855.7AB9C2A6C12C@llvm.org> Author: gclayton Date: Sat Feb 4 20:38:54 2012 New Revision: 149804 URL: http://llvm.org/viewvc/llvm-project?rev=149804&view=rev Log: Fixed "target modules list" (aliased to "image list") to output more information by default. Modified the "target modules list" to have a few new options: "--header" or "-h" => show the image header address "--offset" or "-o" => show the image header address offset from the address in the file (the slide applied to the shared library) Removed the "--symfile-basename" or "-S" option, and repurposed it to "--symfile-unique" "-S" which will show the symbol file if it differs from the executable file. ObjectFile's can now be loaded from memory for cases where we don't have the files cached locally in an SDK or net mounted root. ObjectFileMachO can now read mach files from memory. Moved the section data reading code into the ObjectFile so that the object file can get the section data from Process memory if the file is only in memory. lldb_private::Module can now load its object file in a target with a rigid slide (very common operation for most dynamic linkers) by using: bool Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed) lldb::SBModule() now has a new constructor in the public interface: SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr); This will find an appropriate ObjectFile plug-in to load an image from memory where the object file header is at "header_addr". Modified: lldb/trunk/include/lldb/API/SBModule.h lldb/trunk/include/lldb/API/SBProcess.h lldb/trunk/include/lldb/Core/Module.h lldb/trunk/include/lldb/Core/PluginManager.h lldb/trunk/include/lldb/Core/Section.h lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h lldb/trunk/include/lldb/Symbol/ObjectFile.h lldb/trunk/include/lldb/Target/Process.h lldb/trunk/include/lldb/lldb-private-interfaces.h lldb/trunk/scripts/Python/interface/SBModule.i lldb/trunk/source/API/SBModule.cpp lldb/trunk/source/Commands/CommandObjectTarget.cpp lldb/trunk/source/Core/Module.cpp lldb/trunk/source/Core/ModuleList.cpp lldb/trunk/source/Core/PluginManager.cpp lldb/trunk/source/Core/Section.cpp lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp lldb/trunk/source/Symbol/ObjectFile.cpp lldb/trunk/source/Target/Process.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/include/lldb/API/SBModule.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBModule.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBModule.h (original) +++ lldb/trunk/include/lldb/API/SBModule.h Sat Feb 4 20:38:54 2012 @@ -31,6 +31,9 @@ operator = (const SBModule &rhs); #endif + SBModule (lldb::SBProcess &process, + lldb::addr_t header_addr); + ~SBModule (); bool Modified: lldb/trunk/include/lldb/API/SBProcess.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBProcess.h (original) +++ lldb/trunk/include/lldb/API/SBProcess.h Sat Feb 4 20:38:54 2012 @@ -193,6 +193,7 @@ friend class SBCommandInterpreter; friend class SBDebugger; friend class SBFunction; + friend class SBModule; friend class SBTarget; friend class SBThread; friend class SBValue; Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Sat Feb 4 20:38:54 2012 @@ -96,12 +96,51 @@ const ConstString *object_name = NULL, off_t object_offset = 0); + Module (const FileSpec& file_spec, + const lldb::ProcessSP &processSP, + lldb::addr_t header_addr); //------------------------------------------------------------------ /// Destructor. //------------------------------------------------------------------ virtual ~Module (); + + //------------------------------------------------------------------ + /// Set the load address for all sections in a module to be the + /// file address plus \a slide. + /// + /// Many times a module will be loaded in a target with a constant + /// offset applied to all top level sections. This function can + /// set the load address for all top level sections to be the + /// section file address + offset. + /// + /// @param[in] target + /// The target in which to apply the section load addresses. + /// + /// @param[in] offset + /// The offset to apply to all file addresses for all top + /// level sections in the object file as each section load + /// address is being set. + /// + /// @param[out] changed + /// If any section load addresses were changed in \a target, + /// then \a changed will be set to \b true. Else \a changed + /// will be set to false. This allows this function to be + /// called multiple times on the same module for the same + /// target. If the module hasn't moved, then \a changed will + /// be false and no module updated notification will need to + /// be sent out. + /// + /// @returns + /// /b True if any sections were successfully loaded in \a target, + /// /b false otherwise. + //------------------------------------------------------------------ + bool + SetLoadAddress (Target &target, + lldb::addr_t offset, + bool &changed); + //------------------------------------------------------------------ /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*) /// Modified: lldb/trunk/include/lldb/Core/PluginManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/PluginManager.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/PluginManager.h (original) +++ lldb/trunk/include/lldb/Core/PluginManager.h Sat Feb 4 20:38:54 2012 @@ -137,17 +137,24 @@ static bool RegisterPlugin (const char *name, const char *description, - ObjectFileCreateInstance create_callback); + ObjectFileCreateInstance create_callback, + ObjectFileCreateMemoryInstance create_memory_callback); static bool UnregisterPlugin (ObjectFileCreateInstance create_callback); static ObjectFileCreateInstance GetObjectFileCreateCallbackAtIndex (uint32_t idx); + + static ObjectFileCreateMemoryInstance + GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx); static ObjectFileCreateInstance GetObjectFileCreateCallbackForPluginName (const char *name); + static ObjectFileCreateMemoryInstance + GetObjectFileCreateMemoryCallbackForPluginName (const char *name); + //------------------------------------------------------------------ // ObjectContainer Modified: lldb/trunk/include/lldb/Core/Section.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Section.h (original) +++ lldb/trunk/include/lldb/Core/Section.h Sat Feb 4 20:38:54 2012 @@ -226,15 +226,6 @@ bool IsDescendant (const Section *section); - size_t - MemoryMapSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; - - size_t - ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section_offset, void *dst, size_t dst_len) const; - - size_t - ReadSectionDataFromObjectFile (const ObjectFile* file, DataExtractor& section_data) const; - ConstString& GetName (); Modified: lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h (original) +++ lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h Sat Feb 4 20:38:54 2012 @@ -118,7 +118,7 @@ GetCFIData(); ObjectFile& m_objfile; - lldb::SectionSP m_section; + lldb::SectionSP m_section_sp; lldb::RegisterKind m_reg_kind; Flags m_flags; cie_map_t m_cie_map; Modified: lldb/trunk/include/lldb/Symbol/ObjectFile.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectFile.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ObjectFile.h (original) +++ lldb/trunk/include/lldb/Symbol/ObjectFile.h Sat Feb 4 20:38:54 2012 @@ -91,6 +91,11 @@ lldb::addr_t length, lldb::DataBufferSP& headerDataSP); + ObjectFile (Module* module, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr, + lldb::DataBufferSP& headerDataSP); + //------------------------------------------------------------------ /// Destructor. /// @@ -147,6 +152,29 @@ lldb::DataBufferSP &data_sp); //------------------------------------------------------------------ + /// Find a ObjectFile plug-in that can parse a file in memory. + /// + /// Scans all loaded plug-in interfaces that implement versions of + /// the ObjectFile plug-in interface and returns the first + /// instance that can parse the file. + /// + /// @param[in] module + /// The parent module that owns this object file. + /// + /// @param[in] process_sp + /// A shared pointer to the process whose memory space contains + /// an object file. This will be stored as a std::weak_ptr. + /// + /// @param[in] header_addr + /// The address of the header for the object file in memory. + //------------------------------------------------------------------ + static lldb::ObjectFileSP + FindPlugin (Module* module, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr, + lldb::DataBufferSP &file_data_sp); + + //------------------------------------------------------------------ /// Gets the address size in bytes for the current object file. /// /// @return @@ -372,6 +400,22 @@ GetEntryPointAddress () { return Address();} //------------------------------------------------------------------ + /// Returns the address that represents the header of this object + /// file. + /// + /// The header address is defined as where the header for the object + /// file is that describes the content of the file. If the header + /// doesn't appear in a section that is defined in the object file, + /// an address with no section is returned that has the file offset + /// set in the m_offset member of the lldb_private::Address object. + /// + /// @return + /// Returns the entry address for this module. + //------------------------------------------------------------------ + virtual lldb_private::Address + GetHeaderAddress () { return Address();} + + //------------------------------------------------------------------ /// The object file should be able to calculate its type by looking /// at its file header and possibly the sections or other data in /// the object file. The file type is used in the debugger to help @@ -421,12 +465,33 @@ return m_strata; } + // When an object file is in memory, subclasses should try and lock + // the process weak pointer. If the process weak pointer produces a + // valid ProcessSP, then subclasses can call this function to read + // memory. + static lldb::DataBufferSP + ReadMemory (const lldb::ProcessSP &process_sp, + lldb::addr_t addr, + size_t byte_size); + size_t GetData (off_t offset, size_t length, DataExtractor &data) const; size_t CopyData (off_t offset, size_t length, void *dst) const; + size_t + ReadSectionData (const Section *section, + off_t section_offset, + void *dst, + size_t dst_len) const; + size_t + ReadSectionData (const Section *section, + DataExtractor& section_data) const; + + size_t + MemoryMapSectionData (const Section *section, + DataExtractor& section_data) const; protected: //------------------------------------------------------------------ // Member variables. @@ -438,6 +503,8 @@ lldb::addr_t m_length; ///< The length of this object file if it is known (can be zero if length is unknown or can't be determined). DataExtractor m_data; ///< The data for this object file so things can be parsed lazily. lldb_private::UnwindTable m_unwind_table; /// < Table of FuncUnwinders objects created for this ObjectFile's functions + lldb::ProcessWP m_process_wp; + const bool m_in_memory; //------------------------------------------------------------------ /// Sets the architecture for a module. At present the architecture Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Sat Feb 4 20:38:54 2012 @@ -2574,6 +2574,10 @@ return error; } + lldb::ModuleSP + ReadModuleFromMemory (const FileSpec& file_spec, + lldb::addr_t header_addr); + //------------------------------------------------------------------ /// Attempt to get the attributes for a region of memory in the process. /// Modified: lldb/trunk/include/lldb/lldb-private-interfaces.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-interfaces.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-private-interfaces.h (original) +++ lldb/trunk/include/lldb/lldb-private-interfaces.h Sat Feb 4 20:38:54 2012 @@ -21,6 +21,7 @@ typedef DynamicLoader* (*DynamicLoaderCreateInstance) (Process* process, bool force); typedef ObjectContainer* (*ObjectContainerCreateInstance) (Module* module, lldb::DataBufferSP& dataSP, const FileSpec *file, lldb::addr_t offset, lldb::addr_t length); typedef ObjectFile* (*ObjectFileCreateInstance) (Module* module, lldb::DataBufferSP& dataSP, const FileSpec* file, lldb::addr_t offset, lldb::addr_t length); + typedef ObjectFile* (*ObjectFileCreateMemoryInstance) (Module* module, lldb::DataBufferSP& dataSP, const lldb::ProcessSP &process_sp, lldb::addr_t offset); typedef LogChannel* (*LogChannelCreateInstance) (); typedef EmulateInstruction * (*EmulateInstructionCreateInstance) (const ArchSpec &arch, InstructionType inst_type); typedef OperatingSystem* (*OperatingSystemCreateInstance) (Process *process, bool force); Modified: lldb/trunk/scripts/Python/interface/SBModule.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBModule.i?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBModule.i (original) +++ lldb/trunk/scripts/Python/interface/SBModule.i Sat Feb 4 20:38:54 2012 @@ -98,6 +98,9 @@ SBModule (const SBModule &rhs); + SBModule (lldb::SBProcess &process, + lldb::addr_t header_addr); + ~SBModule (); bool Modified: lldb/trunk/source/API/SBModule.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/API/SBModule.cpp (original) +++ lldb/trunk/source/API/SBModule.cpp Sat Feb 4 20:38:54 2012 @@ -10,6 +10,7 @@ #include "lldb/API/SBModule.h" #include "lldb/API/SBAddress.h" #include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBProcess.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBSymbolContextList.h" #include "lldb/Core/Module.h" @@ -40,6 +41,14 @@ { } +SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : + m_opaque_sp () +{ + ProcessSP process_sp (process.GetSP()); + if (process_sp) + m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr); +} + const SBModule & SBModule::operator = (const SBModule &rhs) { Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Sat Feb 4 20:38:54 2012 @@ -2760,7 +2760,7 @@ Module *module = module_address.GetModulePtr(); if (module) { - PrintModule (strm, module); + PrintModule (target, module, UINT32_MAX, 0, strm); result.SetStatus (eReturnStatusSuccessFinishResult); } else @@ -2808,8 +2808,8 @@ module = module_sp.get(); } - strm.Printf("[%3u] ", image_idx); - PrintModule (strm, module); + int indent = strm.Printf("[%3u] ", image_idx); + PrintModule (target, module, image_idx, indent, strm); } result.SetStatus (eReturnStatusSuccessFinishResult); @@ -2829,108 +2829,160 @@ protected: void - PrintModule (Stream &strm, Module *module) + PrintModule (Target *target, Module *module, uint32_t idx, int indent, Stream &strm) { bool dump_object_name = false; if (m_options.m_format_array.empty()) { - DumpFullpath(strm, &module->GetFileSpec(), 0); - dump_object_name = true; - } - else - { - const size_t num_entries = m_options.m_format_array.size(); - for (size_t i=0; i 0) - strm.PutChar(' '); - char format_char = m_options.m_format_array[i].first; - uint32_t width = m_options.m_format_array[i].second; - switch (format_char) - { - case 'A': - DumpModuleArchitecture (strm, module, false, width); - break; - - case 't': - DumpModuleArchitecture (strm, module, true, width); - break; - - case 'f': - DumpFullpath (strm, &module->GetFileSpec(), width); - dump_object_name = true; - break; - - case 'd': - DumpDirectory (strm, &module->GetFileSpec(), width); - break; - - case 'b': - DumpBasename (strm, &module->GetFileSpec(), width); - dump_object_name = true; - break; - - case 'r': + case 'A': + DumpModuleArchitecture (strm, module, false, width); + break; + + case 't': + DumpModuleArchitecture (strm, module, true, width); + break; + + case 'f': + DumpFullpath (strm, &module->GetFileSpec(), width); + dump_object_name = true; + break; + + case 'd': + DumpDirectory (strm, &module->GetFileSpec(), width); + break; + + case 'b': + DumpBasename (strm, &module->GetFileSpec(), width); + dump_object_name = true; + break; + + case 'h': + case 'o': + // Image header address + { + uint32_t addr_nibble_width = target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16; + + ObjectFile *objfile = module->GetObjectFile (); + if (objfile) { - uint32_t ref_count = 0; - ModuleSP module_sp (module->shared_from_this()); - if (module_sp) + Address header_addr(objfile->GetHeaderAddress()); + if (header_addr.IsValid()) { - // Take one away to make sure we don't count our local "module_sp" - ref_count = module_sp.use_count() - 1; + if (target && !target->GetSectionLoadList().IsEmpty()) + { + lldb::addr_t header_load_addr = header_addr.GetLoadAddress (target); + if (header_load_addr == LLDB_INVALID_ADDRESS) + { + header_addr.Dump (&strm, target, Address::DumpStyleModuleWithFileAddress, Address::DumpStyleFileAddress); + } + else + { + if (format_char == 'o') + { + // Show the offset of slide for the image + strm.Printf ("0x%*.*llx", addr_nibble_width, addr_nibble_width, header_load_addr - header_addr.GetFileAddress()); + } + else + { + // Show the load address of the image + strm.Printf ("0x%*.*llx", addr_nibble_width, addr_nibble_width, header_load_addr); + } + } + break; + } + // The address was valid, but the image isn't loaded, output the address in an appropriate format + header_addr.Dump (&strm, target, Address::DumpStyleFileAddress); + break; } - if (width) - strm.Printf("{%*u}", width, ref_count); - else - strm.Printf("{%u}", ref_count); } - break; + strm.Printf ("%*s", addr_nibble_width + 2, ""); + } + break; + case 'r': + { + uint32_t ref_count = 0; + ModuleSP module_sp (module->shared_from_this()); + if (module_sp) + { + // Take one away to make sure we don't count our local "module_sp" + ref_count = module_sp.use_count() - 1; + } + if (width) + strm.Printf("{%*u}", width, ref_count); + else + strm.Printf("{%u}", ref_count); + } + break; - case 's': - case 'S': + case 's': + case 'S': + { + SymbolVendor *symbol_vendor = module->GetSymbolVendor(); + if (symbol_vendor) { - SymbolVendor *symbol_vendor = module->GetSymbolVendor(); - if (symbol_vendor) + SymbolFile *symbol_file = symbol_vendor->GetSymbolFile(); + if (symbol_file) { - SymbolFile *symbol_file = symbol_vendor->GetSymbolFile(); - if (symbol_file) + if (format_char == 'S') { - if (format_char == 'S') - DumpBasename(strm, &symbol_file->GetObjectFile()->GetFileSpec(), width); - else - DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width); - dump_object_name = true; - break; + FileSpec &symfile_spec = symbol_file->GetObjectFile()->GetFileSpec(); + // Dump symbol file only if different from module file + if (!symfile_spec || symfile_spec == module->GetFileSpec()) + { + print_space = false; + break; + } + // Add a newline and indent past the index + strm.Printf ("\n%*s", indent, ""); } + DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width); + dump_object_name = true; + break; } - strm.Printf("%.*s", width, ""); } - break; - - case 'm': - module->GetModificationTime().Dump(&strm, width); - break; + strm.Printf("%.*s", width, ""); + } + break; + + case 'm': + module->GetModificationTime().Dump(&strm, width); + break; - case 'p': - strm.Printf("%p", module); - break; + case 'p': + strm.Printf("%p", module); + break; - case 'u': - DumpModuleUUID(strm, module); - break; - - default: - break; - } - - } - if (dump_object_name) - { - const char *object_name = module->GetObjectName().GetCString(); - if (object_name) - strm.Printf ("(%s)", object_name); + case 'u': + DumpModuleUUID(strm, module); + break; + + default: + break; } + + } + if (dump_object_name) + { + const char *object_name = module->GetObjectName().GetCString(); + if (object_name) + strm.Printf ("(%s)", object_name); } strm.EOL(); } @@ -2944,12 +2996,14 @@ { LLDB_OPT_SET_1, false, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Display the image at this address."}, { LLDB_OPT_SET_1, false, "arch", 'A', optional_argument, NULL, 0, eArgTypeWidth, "Display the architecture when listing images."}, { LLDB_OPT_SET_1, false, "triple", 't', optional_argument, NULL, 0, eArgTypeWidth, "Display the triple when listing images."}, + { LLDB_OPT_SET_1, false, "header", 'h', no_argument, NULL, 0, eArgTypeNone, "Display the image header address as a load address if debugging, a file address otherwise."}, + { LLDB_OPT_SET_1, false, "offset", 'o', no_argument, NULL, 0, eArgTypeNone, "Display the image header address offset from the header file address (the slide amount)."}, { LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."}, { LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."}, { LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."}, { LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."}, { LLDB_OPT_SET_1, false, "symfile", 's', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."}, - { LLDB_OPT_SET_1, false, "symfile-basename", 'S', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename to the image symbol file with optional width."}, + { LLDB_OPT_SET_1, false, "symfile-unique", 'S', optional_argument, NULL, 0, eArgTypeWidth, "Display the symbol file with optional width only if it is different from the executable object file."}, { LLDB_OPT_SET_1, false, "mod-time", 'm', optional_argument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."}, { LLDB_OPT_SET_1, false, "ref-count", 'r', optional_argument, NULL, 0, eArgTypeWidth, "Display the reference count if the module is still in the shared module cache."}, { LLDB_OPT_SET_1, false, "pointer", 'p', optional_argument, NULL, 0, eArgTypeNone, "Display the module pointer."}, Modified: lldb/trunk/source/Core/Module.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Core/Module.cpp (original) +++ lldb/trunk/source/Core/Module.cpp Sat Feb 4 20:38:54 2012 @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "lldb/Core/Module.h" +#include "lldb/Core/DataBuffer.h" +#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Log.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/RegularExpression.h" @@ -18,6 +20,8 @@ #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/SymbolVendor.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; @@ -111,6 +115,61 @@ #endif +Module::Module(const FileSpec& file_spec, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) : + m_mutex (Mutex::eMutexTypeRecursive), + m_mod_time (), + m_arch (), + m_uuid (), + m_file (file_spec), + m_platform_file(), + m_object_name (), + m_object_offset (), + m_objfile_sp (), + m_symfile_ap (), + m_ast (), + m_did_load_objfile (false), + m_did_load_symbol_vendor (false), + m_did_parse_uuid (false), + m_did_init_ast (false), + m_is_dynamic_loader_module (false), + m_was_modified (false) +{ + // Scope for locker below... + { + Mutex::Locker locker (GetAllocationModuleCollectionMutex()); + GetModuleCollection().push_back(this); + } + StreamString s; + if (m_file.GetFilename()) + s << m_file.GetFilename(); + s.Printf("[0x%16.16llx]", header_addr); + m_file.GetFilename().SetCString (s.GetData()); + Mutex::Locker locker (m_mutex); + DataBufferSP data_sp; + if (process_sp) + { + m_did_load_objfile = true; + std::auto_ptr data_ap (new DataBufferHeap (512, 0)); + Error error; + const size_t bytes_read = process_sp->ReadMemory (header_addr, + data_ap->GetBytes(), + data_ap->GetByteSize(), + error); + if (bytes_read == 512) + { + data_sp.reset (data_ap.release()); + m_objfile_sp = ObjectFile::FindPlugin(this, process_sp, header_addr, data_sp); + if (m_objfile_sp) + { + // Once we get the object file, update our module with the object file's + // architecture since it might differ in vendor/os if some parts were + // unknown. + m_objfile_sp->GetArchitecture (m_arch); + } + } + } +} + Module::Module(const FileSpec& file_spec, const ArchSpec& arch, const ConstString *object_name, off_t object_offset) : m_mutex (Mutex::eMutexTypeRecursive), m_mod_time (file_spec.GetModificationTime()), @@ -977,3 +1036,33 @@ return m_arch == new_arch; } +bool +Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed) +{ + changed = false; + ObjectFile *image_object_file = GetObjectFile(); + if (image_object_file) + { + SectionList *section_list = image_object_file->GetSectionList (); + if (section_list) + { + const size_t num_sections = section_list->GetSize(); + size_t sect_idx = 0; + for (sect_idx = 0; sect_idx < num_sections; ++sect_idx) + { + // Iterate through the object file sections to find the + // first section that starts of file offset zero and that + // has bytes in the file... + Section *section = section_list->GetSectionAtIndex (sect_idx).get(); + if (section) + { + if (target.GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress() + offset)) + changed = true; + } + } + return sect_idx > 0; + } + } + return false; +} + Modified: lldb/trunk/source/Core/ModuleList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Core/ModuleList.cpp (original) +++ lldb/trunk/source/Core/ModuleList.cpp Sat Feb 4 20:38:54 2012 @@ -860,6 +860,8 @@ { error.SetErrorStringWithFormat("'%s' does not exist", path); } + if (error.Fail()) + module_sp.reset(); return error; } Modified: lldb/trunk/source/Core/PluginManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/PluginManager.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Core/PluginManager.cpp (original) +++ lldb/trunk/source/Core/PluginManager.cpp Sat Feb 4 20:38:54 2012 @@ -865,6 +865,8 @@ std::string name; std::string description; ObjectFileCreateInstance create_callback; + ObjectFileCreateMemoryInstance create_memory_callback; + }; typedef std::vector ObjectFileInstances; @@ -889,7 +891,8 @@ ( const char *name, const char *description, - ObjectFileCreateInstance create_callback + ObjectFileCreateInstance create_callback, + ObjectFileCreateMemoryInstance create_memory_callback ) { if (create_callback) @@ -900,6 +903,7 @@ if (description && description[0]) instance.description = description; instance.create_callback = create_callback; + instance.create_memory_callback = create_memory_callback; Mutex::Locker locker (GetObjectFileMutex ()); GetObjectFileInstances ().push_back (instance); } @@ -937,6 +941,17 @@ return NULL; } + +ObjectFileCreateMemoryInstance +PluginManager::GetObjectFileCreateMemoryCallbackAtIndex (uint32_t idx) +{ + Mutex::Locker locker (GetObjectFileMutex ()); + ObjectFileInstances &instances = GetObjectFileInstances (); + if (idx < instances.size()) + return instances[idx].create_memory_callback; + return NULL; +} + ObjectFileCreateInstance PluginManager::GetObjectFileCreateCallbackForPluginName (const char *name) { @@ -957,6 +972,26 @@ } +ObjectFileCreateMemoryInstance +PluginManager::GetObjectFileCreateMemoryCallbackForPluginName (const char *name) +{ + if (name && name[0]) + { + llvm::StringRef name_sref(name); + Mutex::Locker locker (GetObjectFileMutex ()); + ObjectFileInstances &instances = GetObjectFileInstances (); + + ObjectFileInstances::iterator pos, end = instances.end(); + for (pos = instances.begin(); pos != end; ++ pos) + { + if (name_sref.equals (pos->name)) + return pos->create_memory_callback; + } + } + return NULL; +} + + #pragma mark ObjectContainer Modified: lldb/trunk/source/Core/Section.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Core/Section.cpp (original) +++ lldb/trunk/source/Core/Section.cpp Sat Feb 4 20:38:54 2012 @@ -307,35 +307,6 @@ m_name.Dump(s); } -size_t -Section::ReadSectionDataFromObjectFile (const ObjectFile* objfile, off_t section_offset, void *dst, size_t dst_len) const -{ - // The object file now contains a full mmap'ed copy of the object file data, so just use this - if (objfile) - return objfile->CopyData (GetFileOffset() + section_offset, dst_len, dst); - return 0; -} - -//---------------------------------------------------------------------- -// Get the section data the file on disk -//---------------------------------------------------------------------- -size_t -Section::ReadSectionDataFromObjectFile(const ObjectFile* objfile, DataExtractor& section_data) const -{ - // The object file now contains a full mmap'ed copy of the object file data, so just use this - return MemoryMapSectionDataFromObjectFile (objfile, section_data); -} - -size_t -Section::MemoryMapSectionDataFromObjectFile(const ObjectFile* objfile, DataExtractor& section_data) const -{ - // The object file now contains a full mmap'ed copy of the object file data, so just use this - if (objfile) - return objfile->GetData(GetFileOffset(), GetByteSize(), section_data); - section_data.Clear(); - return 0; -} - bool Section::IsDescendant (const Section *section) { Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original) +++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Sat Feb 4 20:38:54 2012 @@ -286,6 +286,10 @@ module_sp = m_process->GetTarget().GetSharedModule (image_info.file_spec, arch, image_info_uuid_is_valid ? &image_info.uuid : NULL); + if (!module_sp || module_sp->GetObjectFile() == NULL) + module_sp = m_process->ReadModuleFromMemory (image_info.file_spec, + image_info.address); + if (did_create_ptr) *did_create_ptr = module_sp; } @@ -752,6 +756,11 @@ NULL, &commpage_dbstr, objfile->GetOffset() + commpage_section->GetFileOffset()); + if (!commpage_image_module_sp || commpage_image_module_sp->GetObjectFile() == NULL) + commpage_image_module_sp = m_process->ReadModuleFromMemory (image_infos[idx].file_spec, + image_infos[idx].address); + + } if (commpage_image_module_sp) UpdateCommPageLoadAddress (commpage_image_module_sp.get()); @@ -1216,6 +1225,9 @@ exe_module_sp = m_process->GetTarget().GetSharedModule (image_infos[exe_idx].file_spec, exe_arch_spec, &image_infos[exe_idx].uuid); + if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) + exe_module_sp = m_process->ReadModuleFromMemory (image_infos[exe_idx].file_spec, + image_infos[exe_idx].address); } if (exe_module_sp) Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Sat Feb 4 20:38:54 2012 @@ -148,7 +148,8 @@ { PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), - CreateInstance); + CreateInstance, + CreateMemoryInstance); } void @@ -196,6 +197,13 @@ } +ObjectFile* +ObjectFileELF::CreateMemoryInstance(Module* module, DataBufferSP& data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr) +{ + return NULL; +} + + //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ @@ -428,8 +436,8 @@ DataExtractor dynsym_data; DataExtractor dynstr_data; - if (dynsym->ReadSectionDataFromObjectFile(this, dynsym_data) && - dynstr->ReadSectionDataFromObjectFile(this, dynstr_data)) + if (ReadSectionData(dynsym, dynsym_data) && + ReadSectionData(dynstr, dynstr_data)) { ELFDynamic symbol; const unsigned section_size = dynsym_data.GetByteSize(); @@ -812,8 +820,8 @@ { DataExtractor symtab_data; DataExtractor strtab_data; - if (symtab->ReadSectionDataFromObjectFile(this, symtab_data) && - strtab->ReadSectionDataFromObjectFile(this, strtab_data)) + if (ReadSectionData(symtab, symtab_data) && + ReadSectionData(strtab, strtab_data)) { num_symbols = ParseSymbols(symbol_table, start_id, section_list, symtab_hdr, @@ -844,7 +852,7 @@ ELFDynamic symbol; DataExtractor dynsym_data; - if (dynsym->ReadSectionDataFromObjectFile(this, dynsym_data)) + if (ReadSectionData(dynsym, dynsym_data)) { const unsigned section_size = dynsym_data.GetByteSize(); @@ -1034,15 +1042,15 @@ return 0; DataExtractor rel_data; - if (!rel_section->ReadSectionDataFromObjectFile(this, rel_data)) + if (!ReadSectionData(rel_section, rel_data)) return 0; DataExtractor symtab_data; - if (!symtab->ReadSectionDataFromObjectFile(this, symtab_data)) + if (!ReadSectionData(symtab, symtab_data)) return 0; DataExtractor strtab_data; - if (!strtab->ReadSectionDataFromObjectFile(this, strtab_data)) + if (!ReadSectionData(strtab, strtab_data)) return 0; unsigned rel_type = PLTRelocationType(); Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (original) +++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h Sat Feb 4 20:38:54 2012 @@ -51,6 +51,12 @@ lldb::addr_t offset, lldb::addr_t length); + static lldb_private::ObjectFile * + CreateMemoryInstance (lldb_private::Module* module, + lldb::DataBufferSP& data_sp, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr); + //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Sat Feb 4 20:38:54 2012 @@ -26,6 +26,7 @@ #include "lldb/Host/FileSpec.h" #include "lldb/Symbol/ClangNamespaceDecl.h" #include "lldb/Symbol/ObjectFile.h" +#include "lldb/Target/Process.h" using namespace lldb; @@ -39,7 +40,8 @@ { PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), - CreateInstance); + CreateInstance, + CreateMemoryInstance); } void @@ -74,6 +76,58 @@ return NULL; } +ObjectFile * +ObjectFileMachO::CreateMemoryInstance (Module* module, + DataBufferSP& data_sp, + const ProcessSP &process_sp, + lldb::addr_t header_addr) +{ + if (ObjectFileMachO::MagicBytesMatch(data_sp, 0, data_sp->GetByteSize())) + { + std::auto_ptr objfile_ap(new ObjectFileMachO (module, data_sp, process_sp, header_addr)); + if (objfile_ap.get() && objfile_ap->ParseHeader()) + return objfile_ap.release(); + } + return NULL; +} + + +const ConstString & +ObjectFileMachO::GetSegmentNameTEXT() +{ + static ConstString g_segment_name_TEXT ("__TEXT"); + return g_segment_name_TEXT; +} + +const ConstString & +ObjectFileMachO::GetSegmentNameDATA() +{ + static ConstString g_segment_name_DATA ("__DATA"); + return g_segment_name_DATA; +} + +const ConstString & +ObjectFileMachO::GetSegmentNameOBJC() +{ + static ConstString g_segment_name_OBJC ("__OBJC"); + return g_segment_name_OBJC; +} + +const ConstString & +ObjectFileMachO::GetSegmentNameLINKEDIT() +{ + static ConstString g_section_name_LINKEDIT ("__LINKEDIT"); + return g_section_name_LINKEDIT; +} + +const ConstString & +ObjectFileMachO::GetSectionNameEHFrame() +{ + static ConstString g_section_name_eh_frame ("__eh_frame"); + return g_section_name_eh_frame; +} + + static uint32_t MachHeaderSizeFromMagic(uint32_t magic) @@ -121,6 +175,20 @@ ::memset (&m_dysymtab, 0, sizeof(m_dysymtab)); } +ObjectFileMachO::ObjectFileMachO (lldb_private::Module* module, + lldb::DataBufferSP& header_data_sp, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr) : + ObjectFile(module, process_sp, header_addr, header_data_sp), + m_mutex (Mutex::eMutexTypeRecursive), + m_header(), + m_sections_ap(), + m_symtab_ap(), + m_entry_point_address () +{ + ::memset (&m_header, 0, sizeof(m_header)); + ::memset (&m_dysymtab, 0, sizeof(m_dysymtab)); +} ObjectFileMachO::~ObjectFileMachO() { @@ -173,7 +241,28 @@ ArchSpec mach_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype); if (SetModulesArchitecture (mach_arch)) - return true; + { + const size_t header_and_lc_size = m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic); + if (m_data.GetByteSize() < header_and_lc_size) + { + DataBufferSP data_sp; + ProcessSP process_sp (m_process_wp.lock()); + if (process_sp) + { + data_sp = ReadMemory (process_sp, m_offset, header_and_lc_size); + } + else + { + // Read in all only the load command data from the file on disk + data_sp = m_file.ReadFileContents(m_offset, header_and_lc_size); + if (data_sp->GetByteSize() != header_and_lc_size) + return false; + } + if (data_sp) + m_data.SetData (data_sp); + } + } + return true; } else { @@ -799,11 +888,45 @@ if (section_list == NULL) return 0; + ProcessSP process_sp (m_process_wp.lock()); + const size_t addr_byte_size = m_data.GetAddressByteSize(); bool bit_width_32 = addr_byte_size == 4; const size_t nlist_byte_size = bit_width_32 ? sizeof(struct nlist) : sizeof(struct nlist_64); - DataExtractor nlist_data (m_data, symtab_load_command.symoff, symtab_load_command.nsyms * nlist_byte_size); + DataExtractor nlist_data (NULL, 0, m_data.GetByteOrder(), m_data.GetAddressByteSize()); + DataExtractor strtab_data (NULL, 0, m_data.GetByteOrder(), m_data.GetAddressByteSize()); + + const addr_t nlist_data_byte_size = symtab_load_command.nsyms * nlist_byte_size; + const addr_t strtab_data_byte_size = symtab_load_command.strsize; + if (process_sp) + { + Target &target = process_sp->GetTarget(); + SectionSP linkedit_section_sp(section_list->FindSectionByName(GetSegmentNameLINKEDIT())); + // Reading mach file from memory in a process or core file... + + if (linkedit_section_sp) + { + const addr_t linkedit_load_addr = linkedit_section_sp->GetLoadBaseAddress(&target); + const addr_t linkedit_file_offset = linkedit_section_sp->GetFileOffset(); + const addr_t symoff_addr = linkedit_load_addr + symtab_load_command.symoff - linkedit_file_offset; + const addr_t stroff_addr = linkedit_load_addr + symtab_load_command.stroff - linkedit_file_offset; + DataBufferSP nlist_data_sp (ReadMemory (process_sp, symoff_addr, nlist_data_byte_size)); + DataBufferSP strtab_data_sp (ReadMemory (process_sp, stroff_addr, strtab_data_byte_size)); + nlist_data.SetData (nlist_data_sp, 0, nlist_data_sp->GetByteSize()); + strtab_data.SetData (strtab_data_sp, 0, strtab_data_sp->GetByteSize()); + } + } + else + { + nlist_data.SetData (m_data, + symtab_load_command.symoff, + nlist_data_byte_size); + strtab_data.SetData (m_data, + symtab_load_command.stroff, + strtab_data_byte_size); + + } if (nlist_data.GetByteSize() == 0) { @@ -812,7 +935,6 @@ return 0; } - DataExtractor strtab_data (m_data, symtab_load_command.stroff, symtab_load_command.strsize); if (strtab_data.GetByteSize() == 0) { @@ -821,10 +943,10 @@ return 0; } - static ConstString g_segment_name_TEXT ("__TEXT"); - static ConstString g_segment_name_DATA ("__DATA"); - static ConstString g_segment_name_OBJC ("__OBJC"); - static ConstString g_section_name_eh_frame ("__eh_frame"); + const ConstString &g_segment_name_TEXT = GetSegmentNameTEXT(); + const ConstString &g_segment_name_DATA = GetSegmentNameDATA(); + const ConstString &g_segment_name_OBJC = GetSegmentNameOBJC(); + const ConstString &g_section_name_eh_frame = GetSectionNameEHFrame(); SectionSP text_section_sp(section_list->FindSectionByName(g_segment_name_TEXT)); SectionSP data_section_sp(section_list->FindSectionByName(g_segment_name_DATA)); SectionSP objc_section_sp(section_list->FindSectionByName(g_segment_name_OBJC)); @@ -1823,6 +1945,24 @@ } +lldb_private::Address +ObjectFileMachO::GetHeaderAddress () +{ + lldb_private::Address header_addr; + SectionList *section_list = GetSectionList(); + if (section_list) + { + SectionSP text_segment_sp (section_list->FindSectionByName (GetSegmentNameTEXT())); + if (text_segment_sp) + { + header_addr.SetSection (text_segment_sp.get()); + header_addr.SetOffset (0); + } + } + return header_addr; +} + + ObjectFile::Type ObjectFileMachO::CalculateType() { Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (original) +++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h Sat Feb 4 20:38:54 2012 @@ -40,13 +40,19 @@ static const char * GetPluginDescriptionStatic(); - static ObjectFile * + static lldb_private::ObjectFile * CreateInstance (lldb_private::Module* module, lldb::DataBufferSP& dataSP, const lldb_private::FileSpec* file, lldb::addr_t offset, lldb::addr_t length); + static lldb_private::ObjectFile * + CreateMemoryInstance (lldb_private::Module* module, + lldb::DataBufferSP& data_sp, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr); + static bool MagicBytesMatch (lldb::DataBufferSP& dataSP, lldb::addr_t offset, @@ -61,6 +67,11 @@ lldb::addr_t offset, lldb::addr_t length); + ObjectFileMachO (lldb_private::Module* module, + lldb::DataBufferSP& dataSP, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr); + virtual ~ObjectFileMachO(); @@ -111,7 +122,10 @@ virtual lldb_private::Address GetEntryPointAddress (); - + + virtual lldb_private::Address + GetHeaderAddress (); + virtual ObjectFile::Type CalculateType(); @@ -123,6 +137,11 @@ llvm::MachO::mach_header m_header; mutable std::auto_ptr m_sections_ap; mutable std::auto_ptr m_symtab_ap; + static const lldb_private::ConstString &GetSegmentNameTEXT(); + static const lldb_private::ConstString &GetSegmentNameDATA(); + static const lldb_private::ConstString &GetSegmentNameOBJC(); + static const lldb_private::ConstString &GetSegmentNameLINKEDIT(); + static const lldb_private::ConstString &GetSectionNameEHFrame(); llvm::MachO::dysymtab_command m_dysymtab; std::vector m_mach_segments; Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Sat Feb 4 20:38:54 2012 @@ -120,7 +120,8 @@ { PluginManager::RegisterPlugin (GetPluginNameStatic(), GetPluginDescriptionStatic(), - CreateInstance); + CreateInstance, + CreateMemoryInstance); } void @@ -155,6 +156,15 @@ return NULL; } +ObjectFile * +ObjectFilePECOFF::CreateMemoryInstance (lldb_private::Module* module, + lldb::DataBufferSP& data_sp, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr) +{ + return NULL; +} + bool ObjectFilePECOFF::MagicBytesMatch (DataBufferSP& dataSP) { Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h (original) +++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h Sat Feb 4 20:38:54 2012 @@ -42,6 +42,11 @@ lldb::addr_t offset, lldb::addr_t length); + static lldb_private::ObjectFile * + CreateMemoryInstance (lldb_private::Module* module, + lldb::DataBufferSP& data_sp, + const lldb::ProcessSP &process_sp, + lldb::addr_t header_addr); static bool MagicBytesMatch (lldb::DataBufferSP& dataSP); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sat Feb 4 20:38:54 2012 @@ -275,7 +275,7 @@ // Memory map the DWARF mach-o segment so we have everything mmap'ed // to keep our heap memory usage down. if (section) - section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data); + m_obj_file->MemoryMapSectionData(section, m_dwarf_data); } get_apple_names_data(); if (m_data_apple_names.GetByteSize() > 0) @@ -460,7 +460,7 @@ } else { - if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0) + if (m_obj_file->ReadSectionData (section, data) == 0) data.Clear(); } } Modified: lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp (original) +++ lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp Sat Feb 4 20:38:54 2012 @@ -27,9 +27,9 @@ using namespace lldb; using namespace lldb_private; -DWARFCallFrameInfo::DWARFCallFrameInfo(ObjectFile& objfile, SectionSP& section, lldb::RegisterKind reg_kind, bool is_eh_frame) : +DWARFCallFrameInfo::DWARFCallFrameInfo(ObjectFile& objfile, SectionSP& section_sp, lldb::RegisterKind reg_kind, bool is_eh_frame) : m_objfile (objfile), - m_section (section), + m_section_sp (section_sp), m_reg_kind (reg_kind), // The flavor of registers that the CFI data uses (enum RegisterKind) m_flags (), m_cie_map (), @@ -68,7 +68,7 @@ bool DWARFCallFrameInfo::GetFDEEntryByAddress (Address addr, FDEEntry& fde_entry) { - if (m_section.get() == NULL || m_section->IsEncrypted()) + if (m_section_sp.get() == NULL || m_section_sp->IsEncrypted()) return false; GetFDEIndex(); @@ -280,7 +280,7 @@ LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); if (log) m_objfile.GetModule()->LogMessage(log.get(), "Reading EH frame info"); - m_section->ReadSectionDataFromObjectFile (&m_objfile, m_cfi_data); + m_objfile.ReadSectionData (m_section_sp.get(), m_cfi_data); m_cfi_data_initialized = true; } } @@ -291,7 +291,7 @@ void DWARFCallFrameInfo::GetFDEIndex () { - if (m_section.get() == NULL || m_section->IsEncrypted()) + if (m_section_sp.get() == NULL || m_section_sp->IsEncrypted()) return; if (m_fde_index_initialized) return; @@ -318,7 +318,7 @@ const CIE *cie = GetCIE (cie_offset); if (cie) { - const lldb::addr_t pc_rel_addr = m_section->GetFileAddress(); + const lldb::addr_t pc_rel_addr = m_section_sp->GetFileAddress(); const lldb::addr_t text_addr = LLDB_INVALID_ADDRESS; const lldb::addr_t data_addr = LLDB_INVALID_ADDRESS; @@ -348,7 +348,7 @@ { dw_offset_t current_entry = offset; - if (m_section.get() == NULL || m_section->IsEncrypted()) + if (m_section_sp.get() == NULL || m_section_sp->IsEncrypted()) return false; if (m_cfi_data_initialized == false) @@ -377,7 +377,7 @@ const dw_offset_t end_offset = current_entry + length + 4; - const lldb::addr_t pc_rel_addr = m_section->GetFileAddress(); + const lldb::addr_t pc_rel_addr = m_section_sp->GetFileAddress(); const lldb::addr_t text_addr = LLDB_INVALID_ADDRESS; const lldb::addr_t data_addr = LLDB_INVALID_ADDRESS; lldb::addr_t range_base = m_cfi_data.GetGNUEHPointer(&offset, cie->ptr_encoding, pc_rel_addr, text_addr, data_addr); Modified: lldb/trunk/source/Symbol/ObjectFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ObjectFile.cpp (original) +++ lldb/trunk/source/Symbol/ObjectFile.cpp Sat Feb 4 20:38:54 2012 @@ -10,6 +10,7 @@ #include "lldb/lldb-private.h" #include "lldb/lldb-private-log.h" #include "lldb/Core/DataBuffer.h" +#include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -18,6 +19,7 @@ #include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/ObjectContainer.h" #include "lldb/Symbol/SymbolFile.h" +#include "lldb/Target/Process.h" using namespace lldb; using namespace lldb_private; @@ -106,6 +108,40 @@ return object_file_sp; } +ObjectFileSP +ObjectFile::FindPlugin (Module* module, + const ProcessSP &process_sp, + lldb::addr_t header_addr, + DataBufferSP &file_data_sp) +{ + Timer scoped_timer (__PRETTY_FUNCTION__, + "ObjectFile::FindPlugin (module = %s/%s, process = %p, header_addr = 0x%llx)", + module->GetFileSpec().GetDirectory().AsCString(), + module->GetFileSpec().GetFilename().AsCString(), + process_sp.get(), header_addr); + ObjectFileSP object_file_sp; + + if (module != NULL) + { + uint32_t idx; + + // Check if this is a normal object file by iterating through + // all object file plugin instances. + ObjectFileCreateMemoryInstance create_callback; + for (idx = 0; (create_callback = PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) != NULL; ++idx) + { + object_file_sp.reset (create_callback(module, file_data_sp, process_sp, header_addr)); + if (object_file_sp.get()) + return object_file_sp; + } + + } + // We didn't find it, so clear our shared pointer in case it + // contains anything and return an empty shared pointer + object_file_sp.reset(); + return object_file_sp; +} + ObjectFile::ObjectFile (Module* module, const FileSpec *file_spec_ptr, addr_t file_offset, @@ -118,7 +154,9 @@ m_offset (file_offset), m_length (file_size), m_data (), - m_unwind_table (*this) + m_unwind_table (*this), + m_process_wp(), + m_in_memory (false) { if (file_spec_ptr) m_file = *file_spec_ptr; @@ -150,6 +188,37 @@ } } + +ObjectFile::ObjectFile (Module* module, + const ProcessSP &process_sp, + lldb::addr_t header_addr, + DataBufferSP& header_data_sp) : + ModuleChild (module), + m_file (), + m_type (eTypeInvalid), + m_strata (eStrataInvalid), + m_offset (header_addr), + m_length (0), + m_data (), + m_unwind_table (*this), + m_process_wp (process_sp), + m_in_memory (true) +{ + if (header_data_sp) + m_data.SetData (header_data_sp, 0, header_data_sp->GetByteSize()); + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); + if (log) + { + log->Printf ("%p ObjectFile::ObjectFile () module = %s/%s, process = %p, header_addr = 0x%llx\n", + this, + m_module->GetFileSpec().GetDirectory().AsCString(), + m_module->GetFileSpec().GetFilename().AsCString(), + process_sp.get(), + m_offset); + } +} + + ObjectFile::~ObjectFile() { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); @@ -276,6 +345,24 @@ return eAddressClassUnknown; } +DataBufferSP +ObjectFile::ReadMemory (const ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size) +{ + DataBufferSP data_sp; + if (process_sp) + { + std::auto_ptr data_ap (new DataBufferHeap (byte_size, 0)); + Error error; + const size_t bytes_read = process_sp->ReadMemory (addr, + data_ap->GetBytes(), + data_ap->GetByteSize(), + error); + if (bytes_read == byte_size) + data_sp.reset (data_ap.release()); + } + return data_sp; +} + size_t ObjectFile::GetData (off_t offset, size_t length, DataExtractor &data) const { @@ -291,3 +378,69 @@ return m_data.CopyByteOrderedData (offset, length, dst, length, lldb::endian::InlHostByteOrder()); } + +size_t +ObjectFile::ReadSectionData (const Section *section, off_t section_offset, void *dst, size_t dst_len) const +{ + if (m_in_memory) + { + ProcessSP process_sp (m_process_wp.lock()); + if (process_sp) + { + Error error; + return process_sp->ReadMemory (section->GetLoadBaseAddress (&process_sp->GetTarget()) + section_offset, dst, dst_len, error); + } + } + else + { + return CopyData (section->GetFileOffset() + section_offset, dst_len, dst); + } + return 0; +} + +//---------------------------------------------------------------------- +// Get the section data the file on disk +//---------------------------------------------------------------------- +size_t +ObjectFile::ReadSectionData (const Section *section, DataExtractor& section_data) const +{ + if (m_in_memory) + { + ProcessSP process_sp (m_process_wp.lock()); + if (process_sp) + { + DataBufferSP data_sp (ReadMemory (process_sp, section->GetLoadBaseAddress (&process_sp->GetTarget()), section->GetByteSize())); + if (data_sp) + { + section_data.SetData (data_sp, 0, data_sp->GetByteSize()); + section_data.SetByteOrder (process_sp->GetByteOrder()); + section_data.SetAddressByteSize (process_sp->GetAddressByteSize()); + return section_data.GetByteSize(); + } + } + } + else + { + // The object file now contains a full mmap'ed copy of the object file data, so just use this + return MemoryMapSectionData (section, section_data); + } + section_data.Clear(); + return 0; +} + +size_t +ObjectFile::MemoryMapSectionData (const Section *section, DataExtractor& section_data) const +{ + if (m_in_memory) + { + return ReadSectionData (section, section_data); + } + else + { + // The object file now contains a full mmap'ed copy of the object file data, so just use this + return GetData(section->GetFileOffset(), section->GetByteSize(), section_data); + } + section_data.Clear(); + return 0; +} + Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sat Feb 4 20:38:54 2012 @@ -2183,6 +2183,18 @@ return error; } +ModuleSP +Process::ReadModuleFromMemory (const FileSpec& file_spec, lldb::addr_t header_addr) +{ + ModuleSP module_sp (new Module (file_spec, shared_from_this(), header_addr)); + if (module_sp) + { + m_target.GetImages().Append(module_sp); + bool changed = false; + module_sp->SetLoadAddress (m_target, 0, changed); + } + return module_sp; +} Error Process::EnableWatchpoint (Watchpoint *watchpoint) Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=149804&r1=149803&r2=149804&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Sat Feb 4 20:38:54 2012 @@ -983,10 +983,10 @@ ObjectFile *objfile = section->GetModule()->GetObjectFile(); if (objfile) { - size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile, - addr.GetOffset(), - dst, - dst_len); + size_t bytes_read = objfile->ReadSectionData (section, + addr.GetOffset(), + dst, + dst_len); if (bytes_read > 0) return bytes_read; else From gclayton at apple.com Sun Feb 5 00:12:47 2012 From: gclayton at apple.com (Greg Clayton) Date: Sun, 05 Feb 2012 06:12:47 -0000 Subject: [Lldb-commits] [lldb] r149811 - /lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Message-ID: <20120205061247.B707B2A6C12C@llvm.org> Author: gclayton Date: Sun Feb 5 00:12:47 2012 New Revision: 149811 URL: http://llvm.org/viewvc/llvm-project?rev=149811&view=rev Log: Added some extra comments for the declaration context comparison function in the DWARF plug-in. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=149811&r1=149810&r2=149811&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sun Feb 5 00:12:47 2012 @@ -4085,6 +4085,18 @@ return type_sp; } +//---------------------------------------------------------------------- +// This function helps to ensure that the declaration contexts match for +// two different DIEs. Often times debug information will refer to a +// forward declaration of a type (the equivalent of "struct my_struct;". +// There will often be a declaration of that type elsewhere that has the +// full definition. When we go looking for the full type "my_struct", we +// will find one or more matches in the accelerator tables and we will +// then need to make sure the type was in the same declaration context +// as the original DIE. This function can efficiently compare two DIEs +// and will return true when the declaration context matches, and false +// when they don't. +//---------------------------------------------------------------------- bool SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) @@ -4092,12 +4104,32 @@ assert (die1 != die2); DWARFDIECollection decl_ctx_1; DWARFDIECollection decl_ctx_2; + //The declaration DIE stack is a stack of the declaration context + // DIEs all the way back to the compile unit. If a type "T" is + // declared inside a class "B", and class "B" is declared inside + // a class "A" and class "A" is in a namespace "lldb", and the + // namespace is in a compile unit, there will be a stack of DIEs: + // + // [0] DW_TAG_class_type for "B" + // [1] DW_TAG_class_type for "A" + // [2] DW_TAG_namespace for "lldb" + // [3] DW_TAG_compile_unit for the source file. + // + // We grab both contexts and make sure that everything matches + // all the way back to the compiler unit. + + // First lets grab the decl contexts for both DIEs die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); + // Make sure the context arrays have the same size, otherwise + // we are done const size_t count1 = decl_ctx_1.Size(); const size_t count2 = decl_ctx_2.Size(); if (count1 != count2) return false; + + // Make sure the DW_TAG values match all the way back up the the + // compile unit. If they don't, then we are done. const DWARFDebugInfoEntry *decl_ctx_die1; const DWARFDebugInfoEntry *decl_ctx_die2; size_t i; @@ -4108,12 +4140,16 @@ if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) return false; } - // Make sure the top item in the decl context die array is always a compile unit #if defined LLDB_CONFIGURATION_DEBUG + + // Make sure the top item in the decl context die array is always + // DW_TAG_compile_unit. If it isn't then something went wrong in + // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); + #endif // Always skip the compile unit when comparing by only iterating up to - // "count1 - 1" + // "count - 1". Here we compare the names as we go. for (i=0; i Author: gclayton Date: Sun Feb 5 00:14:55 2012 New Revision: 149812 URL: http://llvm.org/viewvc/llvm-project?rev=149812&view=rev Log: Made a fix that would affect anything in the anonymous namespace when looking for types and comparing decl context matches. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=149812&r1=149811&r2=149812&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sun Feb 5 00:14:55 2012 @@ -4168,7 +4168,7 @@ if (strcmp(name1, name2) != 0) return false; } - else + else if (name1 || name2) { // One name was NULL while the other wasn't return false; From gclayton at apple.com Sun Feb 5 19:44:55 2012 From: gclayton at apple.com (Greg Clayton) Date: Mon, 06 Feb 2012 01:44:55 -0000 Subject: [Lldb-commits] [lldb] r149853 - in /lldb/trunk: include/lldb/ include/lldb/API/ include/lldb/Core/ include/lldb/Symbol/ scripts/Python/ scripts/Python/interface/ source/API/ source/Plugins/SymbolFile/DWARF/ source/Symbol/ test/python_api/default-constructor/ test/python_api/module_section/ test/python_api/target/ Message-ID: <20120206014456.3200D2A6C12C@llvm.org> Author: gclayton Date: Sun Feb 5 19:44:54 2012 New Revision: 149853 URL: http://llvm.org/viewvc/llvm-project?rev=149853&view=rev Log: Removed all of the "#ifndef SWIG" from the SB header files since we are using interface (.i) files for each class. Changed the FindFunction class from: uint32_t SBTarget::FindFunctions (const char *name, uint32_t name_type_mask, bool append, lldb::SBSymbolContextList& sc_list) uint32_t SBModule::FindFunctions (const char *name, uint32_t name_type_mask, bool append, lldb::SBSymbolContextList& sc_list) To: lldb::SBSymbolContextList SBTarget::FindFunctions (const char *name, uint32_t name_type_mask = lldb::eFunctionNameTypeAny); lldb::SBSymbolContextList SBModule::FindFunctions (const char *name, uint32_t name_type_mask = lldb::eFunctionNameTypeAny); This makes the API easier to use from python. Also added the ability to append a SBSymbolContext or a SBSymbolContextList to a SBSymbolContextList. Exposed properties for lldb.SBSymbolContextList in python: lldb.SBSymbolContextList.modules => list() or all lldb.SBModule objects in the list lldb.SBSymbolContextList.compile_units => list() or all lldb.SBCompileUnits objects in the list lldb.SBSymbolContextList.functions => list() or all lldb.SBFunction objects in the list lldb.SBSymbolContextList.blocks => list() or all lldb.SBBlock objects in the list lldb.SBSymbolContextList.line_entries => list() or all lldb.SBLineEntry objects in the list lldb.SBSymbolContextList.symbols => list() or all lldb.SBSymbol objects in the list This allows a call to the SBTarget::FindFunctions(...) and SBModule::FindFunctions(...) and then the result can be used to extract the desired information: sc_list = lldb.target.FindFunctions("erase") for function in sc_list.functions: print function for symbol in sc_list.symbols: print symbol Exposed properties for the lldb.SBSymbolContext objects in python: lldb.SBSymbolContext.module => lldb.SBModule lldb.SBSymbolContext.compile_unit => lldb.SBCompileUnit lldb.SBSymbolContext.function => lldb.SBFunction lldb.SBSymbolContext.block => lldb.SBBlock lldb.SBSymbolContext.line_entry => lldb.SBLineEntry lldb.SBSymbolContext.symbol => lldb.SBSymbol Exposed properties for the lldb.SBBlock objects in python: lldb.SBBlock.parent => lldb.SBBlock for the parent block that contains lldb.SBBlock.sibling => lldb.SBBlock for the sibling block to the current block lldb.SBBlock.first_child => lldb.SBBlock for the first child block to the current block lldb.SBBlock.call_site => for inline functions, return a lldb.declaration object that gives the call site file, line and column lldb.SBBlock.name => for inline functions this is the name of the inline function that this block represents lldb.SBBlock.inlined_block => returns the inlined function block that contains this block (might return itself if the current block is an inlined block) lldb.SBBlock.range[int] => access the address ranges for a block by index, a list() with start and end address is returned lldb.SBBlock.ranges => an array or all address ranges for this block lldb.SBBlock.num_ranges => the number of address ranges for this blcok SBFunction objects can now get the SBType and the SBBlock that represents the top scope of the function. SBBlock objects can now get the variable list from the current block. The value list returned allows varaibles to be viewed prior with no process if code wants to check the variables in a function. There are two ways to get a variable list from a SBBlock: lldb::SBValueList SBBlock::GetVariables (lldb::SBFrame& frame, bool arguments, bool locals, bool statics, lldb::DynamicValueType use_dynamic); lldb::SBValueList SBBlock::GetVariables (lldb::SBTarget& target, bool arguments, bool locals, bool statics); When a SBFrame is used, the values returned will be locked down to the frame and the values will be evaluated in the context of that frame. When a SBTarget is used, global an static variables can be viewed without a running process. Modified: lldb/trunk/include/lldb/API/SBAddress.h lldb/trunk/include/lldb/API/SBBlock.h lldb/trunk/include/lldb/API/SBBreakpoint.h lldb/trunk/include/lldb/API/SBBreakpointLocation.h lldb/trunk/include/lldb/API/SBBroadcaster.h lldb/trunk/include/lldb/API/SBCommandInterpreter.h lldb/trunk/include/lldb/API/SBCommandReturnObject.h lldb/trunk/include/lldb/API/SBCompileUnit.h lldb/trunk/include/lldb/API/SBData.h lldb/trunk/include/lldb/API/SBDebugger.h lldb/trunk/include/lldb/API/SBError.h lldb/trunk/include/lldb/API/SBEvent.h lldb/trunk/include/lldb/API/SBFileSpec.h lldb/trunk/include/lldb/API/SBFileSpecList.h lldb/trunk/include/lldb/API/SBFrame.h lldb/trunk/include/lldb/API/SBFunction.h lldb/trunk/include/lldb/API/SBInputReader.h lldb/trunk/include/lldb/API/SBInstruction.h lldb/trunk/include/lldb/API/SBInstructionList.h lldb/trunk/include/lldb/API/SBLineEntry.h lldb/trunk/include/lldb/API/SBListener.h lldb/trunk/include/lldb/API/SBModule.h lldb/trunk/include/lldb/API/SBProcess.h lldb/trunk/include/lldb/API/SBSection.h lldb/trunk/include/lldb/API/SBSourceManager.h lldb/trunk/include/lldb/API/SBStream.h lldb/trunk/include/lldb/API/SBStringList.h lldb/trunk/include/lldb/API/SBSymbol.h lldb/trunk/include/lldb/API/SBSymbolContext.h lldb/trunk/include/lldb/API/SBSymbolContextList.h lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/include/lldb/API/SBThread.h lldb/trunk/include/lldb/API/SBType.h lldb/trunk/include/lldb/API/SBValue.h lldb/trunk/include/lldb/API/SBValueList.h lldb/trunk/include/lldb/Core/Module.h lldb/trunk/include/lldb/Symbol/ClangASTType.h lldb/trunk/include/lldb/Symbol/Function.h lldb/trunk/include/lldb/Symbol/SymbolContext.h lldb/trunk/include/lldb/Symbol/Type.h lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/scripts/Python/interface/SBBlock.i lldb/trunk/scripts/Python/interface/SBFunction.i lldb/trunk/scripts/Python/interface/SBModule.i lldb/trunk/scripts/Python/interface/SBSymbolContext.i lldb/trunk/scripts/Python/interface/SBSymbolContextList.i lldb/trunk/scripts/Python/interface/SBTarget.i lldb/trunk/scripts/Python/python-extensions.swig lldb/trunk/source/API/SBAddress.cpp lldb/trunk/source/API/SBBlock.cpp lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/API/SBFunction.cpp lldb/trunk/source/API/SBModule.cpp lldb/trunk/source/API/SBSymbolContext.cpp lldb/trunk/source/API/SBSymbolContextList.cpp lldb/trunk/source/API/SBTarget.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Symbol/SymbolContext.cpp lldb/trunk/source/Symbol/Type.cpp lldb/trunk/test/python_api/default-constructor/sb_module.py lldb/trunk/test/python_api/default-constructor/sb_target.py lldb/trunk/test/python_api/module_section/TestModuleAndSection.py lldb/trunk/test/python_api/target/TestTargetAPI.py Modified: lldb/trunk/include/lldb/API/SBAddress.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBAddress.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBAddress.h (original) +++ lldb/trunk/include/lldb/API/SBAddress.h Sun Feb 5 19:44:54 2012 @@ -30,10 +30,8 @@ ~SBAddress (); -#ifndef SWIG const lldb::SBAddress & operator = (const lldb::SBAddress &rhs); -#endif bool IsValid () const; @@ -119,8 +117,6 @@ friend class SBThread; friend class SBValue; -#ifndef SWIG - lldb_private::Address * operator->(); @@ -136,9 +132,6 @@ const lldb_private::Address & ref() const; -#endif - - SBAddress (const lldb_private::Address *lldb_object_ptr); void Modified: lldb/trunk/include/lldb/API/SBBlock.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBBlock.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBBlock.h (original) +++ lldb/trunk/include/lldb/API/SBBlock.h Sun Feb 5 19:44:54 2012 @@ -11,6 +11,9 @@ #define LLDB_SBBlock_h_ #include "lldb/API/SBDefines.h" +#include "lldb/API/SBFrame.h" +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBValueList.h" namespace lldb { @@ -24,10 +27,8 @@ ~SBBlock (); -#ifndef SWIG const lldb::SBBlock & operator = (const lldb::SBBlock &rhs); -#endif bool IsInlined () const; @@ -67,7 +68,19 @@ uint32_t GetRangeIndexForBlockAddress (lldb::SBAddress block_addr); + + lldb::SBValueList + GetVariables (lldb::SBFrame& frame, + bool arguments, + bool locals, + bool statics, + lldb::DynamicValueType use_dynamic); + lldb::SBValueList + GetVariables (lldb::SBTarget& target, + bool arguments, + bool locals, + bool statics); //------------------------------------------------------------------ /// Get the inlined block that contains this block. /// @@ -87,23 +100,20 @@ private: friend class SBAddress; friend class SBFrame; + friend class SBFunction; friend class SBSymbolContext; -#ifndef SWIG - lldb_private::Block * - get (); + GetPtr (); void - reset (lldb_private::Block *lldb_object_ptr); + SetPtr (lldb_private::Block *lldb_object_ptr); SBBlock (lldb_private::Block *lldb_object_ptr); void AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list); -#endif - lldb_private::Block *m_opaque_ptr; }; Modified: lldb/trunk/include/lldb/API/SBBreakpoint.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBBreakpoint.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBBreakpoint.h (original) +++ lldb/trunk/include/lldb/API/SBBreakpoint.h Sun Feb 5 19:44:54 2012 @@ -29,7 +29,6 @@ ~SBBreakpoint(); -#ifndef SWIG const lldb::SBBreakpoint & operator = (const lldb::SBBreakpoint& rhs); @@ -38,8 +37,6 @@ bool operator == (const lldb::SBBreakpoint& rhs); -#endif - break_id_t GetID () const; @@ -133,8 +130,6 @@ SBBreakpoint (const lldb::BreakpointSP &bp_sp); -#ifndef SWIG - lldb_private::Breakpoint * operator->() const; @@ -147,8 +142,6 @@ const lldb::BreakpointSP & operator *() const; -#endif - static bool PrivateBreakpointHitCallback (void *baton, lldb_private::StoppointCallbackContext *context, Modified: lldb/trunk/include/lldb/API/SBBreakpointLocation.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBBreakpointLocation.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBBreakpointLocation.h (original) +++ lldb/trunk/include/lldb/API/SBBreakpointLocation.h Sun Feb 5 19:44:54 2012 @@ -25,10 +25,8 @@ ~SBBreakpointLocation (); -#ifndef SWIG const lldb::SBBreakpointLocation & operator = (const lldb::SBBreakpointLocation &rhs); -#endif bool IsValid() const; @@ -90,9 +88,7 @@ SBBreakpoint GetBreakpoint (); -#ifndef SWIG SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp); -#endif private: friend class SBBreakpoint; Modified: lldb/trunk/include/lldb/API/SBBroadcaster.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBBroadcaster.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBBroadcaster.h (original) +++ lldb/trunk/include/lldb/API/SBBroadcaster.h Sun Feb 5 19:44:54 2012 @@ -23,10 +23,8 @@ SBBroadcaster (const SBBroadcaster &rhs); -#ifndef SWIG const SBBroadcaster & operator = (const SBBroadcaster &rhs); -#endif ~SBBroadcaster(); @@ -57,7 +55,6 @@ bool RemoveListener (const lldb::SBListener &listener, uint32_t event_mask = UINT32_MAX); -#ifndef SWIG // This comparison is checking if the internal opaque pointer value // is equal to that in "rhs". bool @@ -74,8 +71,6 @@ bool operator < (const lldb::SBBroadcaster &rhs) const; -#endif - protected: friend class SBCommandInterpreter; friend class SBCommunication; @@ -86,16 +81,12 @@ SBBroadcaster (lldb_private::Broadcaster *broadcaster, bool owns); -#ifndef SWIG - lldb_private::Broadcaster * get () const; void reset (lldb_private::Broadcaster *broadcaster, bool owns); -#endif - private: lldb::BroadcasterSP m_opaque_sp; lldb_private::Broadcaster *m_opaque_ptr; Modified: lldb/trunk/include/lldb/API/SBCommandInterpreter.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommandInterpreter.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBCommandInterpreter.h (original) +++ lldb/trunk/include/lldb/API/SBCommandInterpreter.h Sun Feb 5 19:44:54 2012 @@ -28,10 +28,8 @@ SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs); -#ifndef SWIG const lldb::SBCommandInterpreter & operator = (const lldb::SBCommandInterpreter &rhs); -#endif ~SBCommandInterpreter (); @@ -74,7 +72,6 @@ lldb::ReturnStatus HandleCommand (const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history = false); -#ifndef SWIG // This interface is not useful in SWIG, since the cursor & last_char arguments are string pointers INTO current_line // and you can't do that in a scripting language interface in general... int @@ -84,7 +81,7 @@ int match_start_point, int max_return_elements, lldb::SBStringList &matches); -#endif + int HandleCompletion (const char *current_line, uint32_t cursor_pos, Modified: lldb/trunk/include/lldb/API/SBCommandReturnObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommandReturnObject.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBCommandReturnObject.h (original) +++ lldb/trunk/include/lldb/API/SBCommandReturnObject.h Sun Feb 5 19:44:54 2012 @@ -24,8 +24,6 @@ SBCommandReturnObject (const lldb::SBCommandReturnObject &rhs); -#ifndef SWIG - const lldb::SBCommandReturnObject & operator = (const lldb::SBCommandReturnObject &rhs); @@ -34,7 +32,6 @@ lldb_private::CommandReturnObject * Release (); -#endif ~SBCommandReturnObject (); @@ -93,9 +90,6 @@ friend class SBCommandInterpreter; friend class SBOptions; - -#ifndef SWIG - lldb_private::CommandReturnObject * operator->() const; @@ -108,7 +102,6 @@ lldb_private::CommandReturnObject & ref() const; -#endif void SetLLDBObjectPtr (lldb_private::CommandReturnObject *ptr); Modified: lldb/trunk/include/lldb/API/SBCompileUnit.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCompileUnit.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBCompileUnit.h (original) +++ lldb/trunk/include/lldb/API/SBCompileUnit.h Sun Feb 5 19:44:54 2012 @@ -25,10 +25,8 @@ ~SBCompileUnit (); -#ifndef SWIG const lldb::SBCompileUnit & operator = (const lldb::SBCompileUnit &rhs); -#endif bool IsValid () const; @@ -53,16 +51,12 @@ lldb::SBFileSpec *inline_file_spec, bool exact) const; -#ifndef SWIG - bool operator == (const lldb::SBCompileUnit &rhs) const; bool operator != (const lldb::SBCompileUnit &rhs) const; -#endif - bool GetDescription (lldb::SBStream &description); @@ -73,8 +67,6 @@ SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr); -#ifndef SWIG - const lldb_private::CompileUnit * operator->() const; @@ -87,8 +79,6 @@ void reset (lldb_private::CompileUnit *lldb_object_ptr); -#endif - lldb_private::CompileUnit *m_opaque_ptr; }; Modified: lldb/trunk/include/lldb/API/SBData.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBData.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBData.h (original) +++ lldb/trunk/include/lldb/API/SBData.h Sun Feb 5 19:44:54 2012 @@ -22,10 +22,8 @@ SBData (const SBData &rhs); -#ifndef SWIG const SBData & operator = (const SBData &rhs); -#endif ~SBData (); @@ -149,7 +147,6 @@ protected: -#ifndef SWIG // Mimic shared pointer... lldb_private::DataExtractor * get() const; @@ -162,7 +159,6 @@ const lldb::DataExtractorSP & operator*() const; -#endif SBData (const lldb::DataExtractorSP &data_sp); Modified: lldb/trunk/include/lldb/API/SBDebugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBDebugger.h (original) +++ lldb/trunk/include/lldb/API/SBDebugger.h Sun Feb 5 19:44:54 2012 @@ -42,12 +42,10 @@ SBDebugger(const lldb::SBDebugger &rhs); -#ifndef SWIG SBDebugger(const lldb::DebuggerSP &debugger_sp); lldb::SBDebugger & operator = (const lldb::SBDebugger &rhs); -#endif ~SBDebugger(); @@ -245,8 +243,6 @@ private: -#ifndef SWIG - friend class SBInputReader; friend class SBProcess; friend class SBSourceManager; @@ -266,7 +262,6 @@ const lldb::DebuggerSP & get_sp () const; -#endif lldb::DebuggerSP m_opaque_sp; Modified: lldb/trunk/include/lldb/API/SBError.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBError.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBError.h (original) +++ lldb/trunk/include/lldb/API/SBError.h Sun Feb 5 19:44:54 2012 @@ -22,13 +22,9 @@ ~SBError(); -#ifndef SWIG - const SBError & operator =(const lldb::SBError &rhs); -#endif - const char * GetCString () const; @@ -70,7 +66,6 @@ protected: -#ifndef SWIG friend class SBArguments; friend class SBData; friend class SBDebugger; @@ -95,9 +90,6 @@ lldb_private::Error & ref(); -#endif - - void SetError (const lldb_private::Error &lldb_error); Modified: lldb/trunk/include/lldb/API/SBEvent.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBEvent.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBEvent.h (original) +++ lldb/trunk/include/lldb/API/SBEvent.h Sun Feb 5 19:44:54 2012 @@ -32,10 +32,8 @@ ~SBEvent(); -#ifndef SWIG const SBEvent & operator = (const lldb::SBEvent &rhs); -#endif bool IsValid() const; @@ -49,10 +47,8 @@ lldb::SBBroadcaster GetBroadcaster () const; -#ifndef SWIG bool BroadcasterMatchesPtr (const lldb::SBBroadcaster *broadcaster); -#endif bool BroadcasterMatchesRef (const lldb::SBBroadcaster &broadcaster); @@ -63,10 +59,8 @@ static const char * GetCStringFromEvent (const lldb::SBEvent &event); -#ifndef SWIG bool GetDescription (lldb::SBStream &description); -#endif bool GetDescription (lldb::SBStream &description) const; @@ -80,8 +74,6 @@ SBEvent (lldb::EventSP &event_sp); -#ifndef SWIG - lldb::EventSP & GetSP () const; @@ -94,8 +86,6 @@ lldb_private::Event * get () const; -#endif - private: mutable lldb::EventSP m_event_sp; Modified: lldb/trunk/include/lldb/API/SBFileSpec.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFileSpec.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFileSpec.h (original) +++ lldb/trunk/include/lldb/API/SBFileSpec.h Sun Feb 5 19:44:54 2012 @@ -27,10 +27,8 @@ ~SBFileSpec (); -#ifndef SWIG const SBFileSpec & operator = (const lldb::SBFileSpec &rhs); -#endif bool IsValid() const; @@ -70,7 +68,6 @@ void SetFileSpec (const lldb_private::FileSpec& fs); -#ifndef SWIG const lldb_private::FileSpec * operator->() const; @@ -84,8 +81,6 @@ const lldb_private::FileSpec & ref() const; -#endif - std::auto_ptr m_opaque_ap; }; Modified: lldb/trunk/include/lldb/API/SBFileSpecList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFileSpecList.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFileSpecList.h (original) +++ lldb/trunk/include/lldb/API/SBFileSpecList.h Sun Feb 5 19:44:54 2012 @@ -23,10 +23,8 @@ ~SBFileSpecList (); -#ifndef SWIG const SBFileSpecList & operator = (const lldb::SBFileSpecList &rhs); -#endif uint32_t GetSize () const; @@ -53,8 +51,6 @@ friend class SBTarget; -#ifndef SWIG - const lldb_private::FileSpecList * operator->() const; @@ -67,8 +63,6 @@ const lldb_private::FileSpecList & ref() const; -#endif - std::auto_ptr m_opaque_ap; }; Modified: lldb/trunk/include/lldb/API/SBFrame.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFrame.h (original) +++ lldb/trunk/include/lldb/API/SBFrame.h Sun Feb 5 19:44:54 2012 @@ -24,10 +24,8 @@ SBFrame (const lldb::SBFrame &rhs); -#ifndef SWIG const lldb::SBFrame & operator =(const lldb::SBFrame &rhs); -#endif ~SBFrame(); @@ -130,15 +128,12 @@ void Clear(); -#ifndef SWIG bool operator == (const lldb::SBFrame &rhs) const; bool operator != (const lldb::SBFrame &rhs) const; -#endif - /// The version that doesn't supply a 'use_dynamic' value will use the /// target's default. lldb::SBValueList @@ -208,16 +203,14 @@ bool GetDescription (lldb::SBStream &description); -#ifndef SWIG SBFrame (const lldb::StackFrameSP &lldb_object_sp); -#endif protected: - friend class SBValue; -private: - friend class SBThread; + friend class SBBlock; friend class SBInstruction; + friend class SBThread; + friend class SBValue; #ifndef LLDB_DISABLE_PYTHON friend class lldb_private::ScriptInterpreterPython; #endif Modified: lldb/trunk/include/lldb/API/SBFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFunction.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFunction.h (original) +++ lldb/trunk/include/lldb/API/SBFunction.h Sun Feb 5 19:44:54 2012 @@ -24,11 +24,8 @@ SBFunction (const lldb::SBFunction &rhs); -#ifndef SWIG const lldb::SBFunction & operator = (const lldb::SBFunction &rhs); -#endif - ~SBFunction (); @@ -44,38 +41,38 @@ lldb::SBInstructionList GetInstructions (lldb::SBTarget target); - SBAddress + lldb::SBAddress GetStartAddress (); - SBAddress + lldb::SBAddress GetEndAddress (); uint32_t GetPrologueByteSize (); -#ifndef SWIG + lldb::SBType + GetType (); + + lldb::SBBlock + GetBlock (); + bool operator == (const lldb::SBFunction &rhs) const; bool operator != (const lldb::SBFunction &rhs) const; -#endif bool GetDescription (lldb::SBStream &description); protected: -#ifndef SWIG - lldb_private::Function * get (); void reset (lldb_private::Function *lldb_object_ptr); -#endif - private: friend class SBAddress; friend class SBFrame; Modified: lldb/trunk/include/lldb/API/SBInputReader.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInputReader.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBInputReader.h (original) +++ lldb/trunk/include/lldb/API/SBInputReader.h Sun Feb 5 19:44:54 2012 @@ -45,10 +45,8 @@ bool IsValid () const; -#ifndef SWIG const lldb::SBInputReader & operator = (const lldb::SBInputReader &rhs); -#endif bool IsActive () const; @@ -65,8 +63,6 @@ protected: friend class SBDebugger; -#ifndef SWIG - lldb_private::InputReader * operator->() const; @@ -82,9 +78,6 @@ lldb_private::InputReader & ref() const; -#endif - - private: static size_t Modified: lldb/trunk/include/lldb/API/SBInstruction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstruction.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBInstruction.h (original) +++ lldb/trunk/include/lldb/API/SBInstruction.h Sun Feb 5 19:44:54 2012 @@ -28,10 +28,8 @@ SBInstruction (const SBInstruction &rhs); -#ifndef SWIG const SBInstruction & operator = (const SBInstruction &rhs); -#endif ~SBInstruction (); Modified: lldb/trunk/include/lldb/API/SBInstructionList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBInstructionList.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBInstructionList.h (original) +++ lldb/trunk/include/lldb/API/SBInstructionList.h Sun Feb 5 19:44:54 2012 @@ -24,10 +24,8 @@ SBInstructionList (const SBInstructionList &rhs); -#ifndef SWIG const SBInstructionList & operator = (const SBInstructionList &rhs); -#endif ~SBInstructionList (); Modified: lldb/trunk/include/lldb/API/SBLineEntry.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBLineEntry.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBLineEntry.h (original) +++ lldb/trunk/include/lldb/API/SBLineEntry.h Sun Feb 5 19:44:54 2012 @@ -26,10 +26,8 @@ ~SBLineEntry (); -#ifndef SWIG const lldb::SBLineEntry & operator = (const lldb::SBLineEntry &rhs); -#endif lldb::SBAddress GetStartAddress () const; @@ -58,15 +56,12 @@ void SetColumn (uint32_t column); -#ifndef SWIG bool operator == (const lldb::SBLineEntry &rhs) const; bool operator != (const lldb::SBLineEntry &rhs) const; -#endif - bool GetDescription (lldb::SBStream &description); @@ -81,8 +76,6 @@ friend class SBFrame; friend class SBSymbolContext; -#ifndef SWIG - const lldb_private::LineEntry * operator->() const; @@ -92,9 +85,6 @@ const lldb_private::LineEntry & ref() const; -#endif - - SBLineEntry (const lldb_private::LineEntry *lldb_object_ptr); void Modified: lldb/trunk/include/lldb/API/SBListener.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBListener.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBListener.h (original) +++ lldb/trunk/include/lldb/API/SBListener.h Sun Feb 5 19:44:54 2012 @@ -25,10 +25,8 @@ ~SBListener (); -#ifndef SWIG const lldb::SBListener & operator = (const lldb::SBListener &rhs); -#endif void AddEvent (const lldb::SBEvent &event); @@ -100,8 +98,6 @@ private: -#ifndef SWIG - lldb_private::Listener * operator->() const; @@ -120,8 +116,6 @@ void reset(lldb_private::Listener *listener, bool transfer_ownership); -#endif - lldb::ListenerSP m_opaque_sp; lldb_private::Listener *m_opaque_ptr; }; Modified: lldb/trunk/include/lldb/API/SBModule.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBModule.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBModule.h (original) +++ lldb/trunk/include/lldb/API/SBModule.h Sun Feb 5 19:44:54 2012 @@ -25,11 +25,9 @@ SBModule (); SBModule (const SBModule &rhs); - -#ifndef SWIG + const SBModule & operator = (const SBModule &rhs); -#endif SBModule (lldb::SBProcess &process, lldb::addr_t header_addr); @@ -85,22 +83,18 @@ const char * GetTriple (); -#ifndef SWIG const uint8_t * GetUUIDBytes () const; -#endif const char * GetUUIDString () const; -#ifndef SWIG bool operator == (const lldb::SBModule &rhs) const; bool operator != (const lldb::SBModule &rhs) const; -#endif lldb::SBSection FindSection (const char *sect_name); @@ -138,22 +132,13 @@ /// C++ methods, or ObjC selectors. /// See FunctionNameType for more details. /// - /// @param[in] append - /// If true, any matches will be appended to \a sc_list, else - /// matches replace the contents of \a sc_list. - /// - /// @param[out] sc_list - /// A symbol context list that gets filled in with all of the - /// matches. - /// /// @return - /// The number of matches added to \a sc_list. + /// A lldb::SBSymbolContextList that gets filled in with all of + /// the symbol contexts for all the matches. //------------------------------------------------------------------ - uint32_t + lldb::SBSymbolContextList FindFunctions (const char *name, - uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits - bool append, - lldb::SBSymbolContextList& sc_list); + uint32_t name_type_mask = lldb::eFunctionNameTypeAny); //------------------------------------------------------------------ /// Find global and static variables by name. Modified: lldb/trunk/include/lldb/API/SBProcess.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBProcess.h (original) +++ lldb/trunk/include/lldb/API/SBProcess.h Sun Feb 5 19:44:54 2012 @@ -37,10 +37,8 @@ SBProcess (const lldb::SBProcess& rhs); -#ifndef SWIG const lldb::SBProcess& operator = (const lldb::SBProcess& rhs); -#endif ~SBProcess(); Modified: lldb/trunk/include/lldb/API/SBSection.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSection.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBSection.h (original) +++ lldb/trunk/include/lldb/API/SBSection.h Sun Feb 5 19:44:54 2012 @@ -25,10 +25,9 @@ ~SBSection (); -#ifndef SWIG const lldb::SBSection & operator = (const lldb::SBSection &rhs); -#endif + bool IsValid () const; @@ -66,21 +65,17 @@ SectionType GetSectionType (); -#ifndef SWIG bool operator == (const lldb::SBSection &rhs); bool operator != (const lldb::SBSection &rhs); -#endif - bool GetDescription (lldb::SBStream &description); private: -#ifndef SWIG friend class SBAddress; friend class SBModule; friend class SBTarget; @@ -92,7 +87,6 @@ void SetSection (const lldb_private::Section *section); -#endif std::auto_ptr m_opaque_ap; }; Modified: lldb/trunk/include/lldb/API/SBSourceManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSourceManager.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBSourceManager.h (original) +++ lldb/trunk/include/lldb/API/SBSourceManager.h Sun Feb 5 19:44:54 2012 @@ -25,10 +25,8 @@ ~SBSourceManager(); -#ifndef SWIG const lldb::SBSourceManager & operator = (const lldb::SBSourceManager &rhs); -#endif size_t DisplaySourceLinesWithLineNumbers (const lldb::SBFileSpec &file, Modified: lldb/trunk/include/lldb/API/SBStream.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStream.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBStream.h (original) +++ lldb/trunk/include/lldb/API/SBStream.h Sun Feb 5 19:44:54 2012 @@ -79,6 +79,7 @@ friend class SBSourceManager; friend class SBSymbol; friend class SBSymbolContext; + friend class SBSymbolContextList; friend class SBTarget; friend class SBThread; friend class SBType; @@ -86,8 +87,6 @@ friend class SBValue; friend class SBWatchpoint; -#ifndef SWIG - lldb_private::Stream * operator->(); @@ -97,8 +96,6 @@ lldb_private::Stream & ref(); -#endif - private: DISALLOW_COPY_AND_ASSIGN (SBStream); Modified: lldb/trunk/include/lldb/API/SBStringList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStringList.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBStringList.h (original) +++ lldb/trunk/include/lldb/API/SBStringList.h Sun Feb 5 19:44:54 2012 @@ -22,10 +22,8 @@ SBStringList (const lldb::SBStringList &rhs); -#ifndef SWIG const SBStringList & operator = (const SBStringList &rhs); -#endif ~SBStringList (); @@ -55,16 +53,12 @@ SBStringList (const lldb_private::StringList *lldb_strings); -#ifndef SWIG - const lldb_private::StringList * operator->() const; const lldb_private::StringList & operator*() const; -#endif - private: std::auto_ptr m_opaque_ap; Modified: lldb/trunk/include/lldb/API/SBSymbol.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSymbol.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBSymbol.h (original) +++ lldb/trunk/include/lldb/API/SBSymbol.h Sun Feb 5 19:44:54 2012 @@ -27,10 +27,8 @@ SBSymbol (const lldb::SBSymbol &rhs); -#ifndef SWIG const lldb::SBSymbol & operator = (const lldb::SBSymbol &rhs); -#endif bool IsValid () const; @@ -57,26 +55,22 @@ SymbolType GetType (); -#ifndef SWIG bool operator == (const lldb::SBSymbol &rhs) const; bool operator != (const lldb::SBSymbol &rhs) const; -#endif bool GetDescription (lldb::SBStream &description); protected: -#ifndef SWIG lldb_private::Symbol * get (); void reset (lldb_private::Symbol *); -#endif private: friend class SBAddress; Modified: lldb/trunk/include/lldb/API/SBSymbolContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSymbolContext.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBSymbolContext.h (original) +++ lldb/trunk/include/lldb/API/SBSymbolContext.h Sun Feb 5 19:44:54 2012 @@ -32,10 +32,8 @@ bool IsValid () const; -#ifndef SWIG const lldb::SBSymbolContext & operator = (const lldb::SBSymbolContext &rhs); -#endif lldb::SBModule GetModule (); lldb::SBCompileUnit GetCompileUnit (); @@ -66,8 +64,6 @@ friend class SBTarget; friend class SBSymbolContextList; -#ifndef SWIG - lldb_private::SymbolContext* operator->() const; @@ -80,8 +76,6 @@ const lldb_private::SymbolContext& operator*() const; -#endif - lldb_private::SymbolContext * get() const; Modified: lldb/trunk/include/lldb/API/SBSymbolContextList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBSymbolContextList.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBSymbolContextList.h (original) +++ lldb/trunk/include/lldb/API/SBSymbolContextList.h Sun Feb 5 19:44:54 2012 @@ -24,10 +24,8 @@ ~SBSymbolContextList (); -#ifndef SWIG const lldb::SBSymbolContextList & operator = (const lldb::SBSymbolContextList &rhs); -#endif bool IsValid () const; @@ -35,10 +33,19 @@ uint32_t GetSize() const; - SBSymbolContext + lldb::SBSymbolContext GetContextAtIndex (uint32_t idx); + + bool + GetDescription (lldb::SBStream &description); void + Append (lldb::SBSymbolContext &sc); + + void + Append (lldb::SBSymbolContextList &sc_list); + + void Clear(); protected: @@ -46,16 +53,12 @@ friend class SBModule; friend class SBTarget; -#ifndef SWIG - lldb_private::SymbolContextList* operator->() const; lldb_private::SymbolContextList& operator*() const; -#endif - private: std::auto_ptr m_opaque_ap; }; Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Sun Feb 5 19:44:54 2012 @@ -42,10 +42,8 @@ SBTarget (const lldb::SBTarget& rhs); -#ifndef SWIG const lldb::SBTarget& operator = (const lldb::SBTarget& rhs); -#endif //------------------------------------------------------------------ // Destructor @@ -361,22 +359,13 @@ /// C++ methods, or ObjC selectors. /// See FunctionNameType for more details. /// - /// @param[in] append - /// If true, any matches will be appended to \a sc_list, else - /// matches replace the contents of \a sc_list. - /// - /// @param[out] sc_list - /// A symbol context list that gets filled in with all of the - /// matches. - /// /// @return - /// The number of matches added to \a sc_list. + /// A lldb::SBSymbolContextList that gets filled in with all of + /// the symbol contexts for all the matches. //------------------------------------------------------------------ - uint32_t + lldb::SBSymbolContextList FindFunctions (const char *name, - uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits - bool append, - lldb::SBSymbolContextList& sc_list); + uint32_t name_type_mask = lldb::eFunctionNameTypeAny); //------------------------------------------------------------------ /// Find global and static variables by name. @@ -510,20 +499,18 @@ lldb::SBInstructionList GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size); -#ifndef SWIG bool operator == (const lldb::SBTarget &rhs) const; bool operator != (const lldb::SBTarget &rhs) const; -#endif - bool GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); protected: friend class SBAddress; + friend class SBBlock; friend class SBDebugger; friend class SBFunction; friend class SBInstruction; Modified: lldb/trunk/include/lldb/API/SBThread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBThread.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBThread.h (original) +++ lldb/trunk/include/lldb/API/SBThread.h Sun Feb 5 19:44:54 2012 @@ -147,8 +147,6 @@ lldb::SBProcess GetProcess (); -#ifndef SWIG - const lldb::SBThread & operator = (const lldb::SBThread &rhs); @@ -158,8 +156,6 @@ bool operator != (const lldb::SBThread &rhs) const; -#endif - bool GetDescription (lldb::SBStream &description) const; Modified: lldb/trunk/include/lldb/API/SBType.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBType.h (original) +++ lldb/trunk/include/lldb/API/SBType.h Sun Feb 5 19:44:54 2012 @@ -24,11 +24,9 @@ SBTypeMember (const lldb::SBTypeMember& rhs); ~SBTypeMember(); - -#ifndef SWIG + lldb::SBTypeMember& operator = (const lldb::SBTypeMember& rhs); -#endif bool IsValid() const; @@ -52,7 +50,6 @@ protected: friend class SBType; -#ifndef SWIG void reset (lldb_private::TypeMemberImpl *); @@ -61,7 +58,6 @@ const lldb_private::TypeMemberImpl & ref () const; -#endif std::auto_ptr m_opaque_ap; }; @@ -147,7 +143,6 @@ GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); -#ifndef SWIG lldb::SBType & operator = (const lldb::SBType &rhs); @@ -156,11 +151,9 @@ bool operator != (lldb::SBType &rhs); -#endif protected: - -#ifndef SWIG + lldb_private::TypeImpl & ref (); @@ -171,17 +164,16 @@ GetSP (); void - SetSP (const lldb::TypeImplSP &type_impl_sp); -#endif - + SetSP (const lldb::TypeImplSP &type_impl_sp); lldb::TypeImplSP m_opaque_sp; + friend class SBFunction; friend class SBModule; friend class SBTarget; - friend class SBValue; friend class SBTypeMember; friend class SBTypeList; + friend class SBValue; SBType (const lldb_private::ClangASTType &); SBType (const lldb::TypeSP &); Modified: lldb/trunk/include/lldb/API/SBValue.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBValue.h (original) +++ lldb/trunk/include/lldb/API/SBValue.h Sun Feb 5 19:44:54 2012 @@ -24,10 +24,8 @@ SBValue (const lldb::SBValue &rhs); -#ifndef SWIG lldb::SBValue & operator =(const lldb::SBValue &rhs); -#endif ~SBValue (); @@ -339,7 +337,6 @@ lldb::SBWatchpoint WatchPointee (bool resolve_location, bool read, bool write); -#ifndef SWIG // this must be defined in the .h file because synthetic children as implemented in the core // currently rely on being able to extract the SharedPointer out of an SBValue. if the implementation // is deferred to the .cpp file instead of being inlined here, the platform will fail to link @@ -349,7 +346,6 @@ { return m_opaque_sp; } -#endif protected: friend class SBValueList; Modified: lldb/trunk/include/lldb/API/SBValueList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValueList.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBValueList.h (original) +++ lldb/trunk/include/lldb/API/SBValueList.h Sun Feb 5 19:44:54 2012 @@ -45,8 +45,6 @@ lldb::SBValue FindValueObjectByUID (lldb::user_id_t uid); - -#ifndef SWIG const lldb::SBValueList & operator = (const lldb::SBValueList &rhs); @@ -68,8 +66,6 @@ lldb_private::ValueObjectList & ref (); -#endif - private: friend class SBFrame; Modified: lldb/trunk/include/lldb/Core/Module.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Module.h (original) +++ lldb/trunk/include/lldb/Core/Module.h Sun Feb 5 19:44:54 2012 @@ -132,7 +132,7 @@ /// be false and no module updated notification will need to /// be sent out. /// - /// @returns + /// @return /// /b True if any sections were successfully loaded in \a target, /// /b false otherwise. //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Sun Feb 5 19:44:54 2012 @@ -310,6 +310,13 @@ static lldb::clang_type_t RemoveFastQualifiers (lldb::clang_type_t); + void + Clear() + { + m_type = NULL; + m_ast = NULL; + } + private: lldb::clang_type_t m_type; clang::ASTContext *m_ast; Modified: lldb/trunk/include/lldb/Symbol/Function.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Function.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Function.h (original) +++ lldb/trunk/include/lldb/Symbol/Function.h Sun Feb 5 19:44:54 2012 @@ -463,7 +463,7 @@ /// @param[out] line_no /// The line number. //------------------------------------------------------------------ - void + void GetEndLineSourceInfo (FileSpec &source_file, uint32_t &line_no); //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Symbol/SymbolContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolContext.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/SymbolContext.h (original) +++ lldb/trunk/include/lldb/Symbol/SymbolContext.h Sun Feb 5 19:44:54 2012 @@ -361,9 +361,16 @@ void Append (const SymbolContext& sc); + void + Append (const SymbolContextList& sc_list); + bool - AppendIfUnique (const SymbolContext& sc, bool merge_symbol_into_function); + AppendIfUnique (const SymbolContext& sc, + bool merge_symbol_into_function); + uint32_t + AppendIfUnique (const SymbolContextList& sc_list, + bool merge_symbol_into_function); //------------------------------------------------------------------ /// Clear the object's state. /// @@ -418,6 +425,11 @@ uint32_t NumLineEntriesWithLine (uint32_t line) const; + void + GetDescription(Stream *s, + lldb::DescriptionLevel level, + Target *target) const; + protected: typedef std::vector collection; ///< The collection type for the list. Modified: lldb/trunk/include/lldb/Symbol/Type.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Type.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Type.h (original) +++ lldb/trunk/include/lldb/Symbol/Type.h Sun Feb 5 19:44:54 2012 @@ -390,6 +390,8 @@ GetDescription (lldb_private::Stream &strm, lldb::DescriptionLevel description_level); + void + SetType (const lldb::TypeSP &type_sp); private: ClangASTType m_clang_ast_type; Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Sun Feb 5 19:44:54 2012 @@ -512,7 +512,11 @@ eFunctionNameTypeBase = (1u << 3), // The function name only, no namespaces or arguments and no class // methods or selectors will be searched. eFunctionNameTypeMethod = (1u << 4), // Find function by method name (C++) with no namespace or arguments - eFunctionNameTypeSelector = (1u << 5) // Find function by selector name (ObjC) names + eFunctionNameTypeSelector = (1u << 5), // Find function by selector name (ObjC) names + eFunctionNameTypeAny = (eFunctionNameTypeFull | + eFunctionNameTypeBase | + eFunctionNameTypeMethod | + eFunctionNameTypeSelector ) } FunctionNameType; Modified: lldb/trunk/scripts/Python/interface/SBBlock.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBBlock.i?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBBlock.i (original) +++ lldb/trunk/scripts/Python/interface/SBBlock.i Sun Feb 5 19:44:54 2012 @@ -89,6 +89,87 @@ bool GetDescription (lldb::SBStream &description); + + lldb::SBValueList + GetVariables (lldb::SBFrame& frame, + bool arguments, + bool locals, + bool statics, + lldb::DynamicValueType use_dynamic); + + lldb::SBValueList + GetVariables (lldb::SBTarget& target, + bool arguments, + bool locals, + bool statics); + + %pythoncode %{ + def get_range_at_index(self, idx): + if idx < self.GetNumRanges(): + return [self.sbblock.GetRangeStartAddress(key), self.sbblock.GetRangeEndAddress(key)] + return [] + + class ranges_access(object): + '''A helper object that will lazily hand out an array of lldb.SBAddress that represent address ranges for a block.''' + def __init__(self, sbblock): + self.sbblock = sbblock + + def __len__(self): + if self.sbblock: + return self.sbblock.GetNumRanges() + return 0 + + def __getitem__(self, key): + count = len(self) + if type(key) is int: + return self.sbblock.get_range_at_index (key); + else: + print "error: unsupported item type: %s" % type(key) + return None + + def get_ranges_access_object(self): + '''An accessor function that returns a ranges_access() object which allows lazy block address ranges access.''' + return self.ranges_access (self) + + def get_ranges_array(self): + '''An accessor function that returns an array object that contains all ranges in this block object.''' + if not hasattr(self, 'ranges'): + self.ranges = [] + for idx in range(self.num_ranges): + self.ranges.append (self.get_range_at_index (idx)) + return self.ranges + + def get_call_site(self): + return declaration(self.GetInlinedCallSiteFile(), self.GetInlinedCallSiteLine(), self.GetInlinedCallSiteColumn()) + + __swig_getmethods__["parent"] = GetParent + if _newclass: x = property(GetParent, None) + + __swig_getmethods__["first_child"] = GetFirstChild + if _newclass: x = property(GetFirstChild, None) + + __swig_getmethods__["call_site"] = get_call_site + if _newclass: x = property(get_call_site, None) + + __swig_getmethods__["sibling"] = GetSibling + if _newclass: x = property(GetSibling, None) + + __swig_getmethods__["name"] = GetInlinedName + if _newclass: x = property(GetInlinedName, None) + + __swig_getmethods__["inlined_block"] = GetContainingInlinedBlock + if _newclass: x = property(GetContainingInlinedBlock, None) + + __swig_getmethods__["range"] = get_ranges_access_object + if _newclass: x = property(get_ranges_access_object, None) + + __swig_getmethods__["ranges"] = get_ranges_array + if _newclass: x = property(get_ranges_array, None) + + __swig_getmethods__["num_ranges"] = GetNumRanges + if _newclass: x = property(GetNumRanges, None) + %} + }; } // namespace lldb Modified: lldb/trunk/scripts/Python/interface/SBFunction.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBFunction.i?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBFunction.i (original) +++ lldb/trunk/scripts/Python/interface/SBFunction.i Sun Feb 5 19:44:54 2012 @@ -65,15 +65,21 @@ lldb::SBInstructionList GetInstructions (lldb::SBTarget target); - SBAddress + lldb::SBAddress GetStartAddress (); - SBAddress + lldb::SBAddress GetEndAddress (); uint32_t GetPrologueByteSize (); + lldb::SBType + GetType (); + + lldb::SBBlock + GetBlock (); + bool GetDescription (lldb::SBStream &description); @@ -81,24 +87,29 @@ def get_instructions_from_current_target (self): return self.GetInstructions (target) - __swig_getmethods__["name"] = GetName - if _newclass: x = property(GetName, None) - - __swig_getmethods__["mangled"] = GetMangledName - if _newclass: x = property(GetMangledName, None) - __swig_getmethods__["addr"] = GetStartAddress if _newclass: x = property(GetStartAddress, None) - + + __swig_getmethods__["block"] = GetBlock + if _newclass: x = property(GetBlock, None) + __swig_getmethods__["end_addr"] = GetEndAddress if _newclass: x = property(GetEndAddress, None) - __swig_getmethods__["prologue_size"] = GetPrologueByteSize - if _newclass: x = property(GetPrologueByteSize, None) - __swig_getmethods__["instructions"] = get_instructions_from_current_target if _newclass: x = property(get_instructions_from_current_target, None) + __swig_getmethods__["mangled"] = GetMangledName + if _newclass: x = property(GetMangledName, None) + + __swig_getmethods__["name"] = GetName + if _newclass: x = property(GetName, None) + + __swig_getmethods__["prologue_size"] = GetPrologueByteSize + if _newclass: x = property(GetPrologueByteSize, None) + + __swig_getmethods__["type"] = GetType + if _newclass: x = property(GetType, None) %} }; Modified: lldb/trunk/scripts/Python/interface/SBModule.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBModule.i?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBModule.i (original) +++ lldb/trunk/scripts/Python/interface/SBModule.i Sun Feb 5 19:44:54 2012 @@ -192,23 +192,14 @@ /// C++ methods, or ObjC selectors. /// See FunctionNameType for more details. /// - /// @param[in] append - /// If true, any matches will be appended to \a sc_list, else - /// matches replace the contents of \a sc_list. - /// - /// @param[out] sc_list + /// @return /// A symbol context list that gets filled in with all of the /// matches. - /// - /// @return - /// The number of matches added to \a sc_list. //------------------------------------------------------------------ ") FindFunctions; - uint32_t + lldb::SBSymbolContextList FindFunctions (const char *name, - uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits - bool append, - lldb::SBSymbolContextList& sc_list); + uint32_t name_type_mask = lldb::eFunctionNameTypeAny); lldb::SBType FindFirstType (const char* name); Modified: lldb/trunk/scripts/Python/interface/SBSymbolContext.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBSymbolContext.i?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBSymbolContext.i (original) +++ lldb/trunk/scripts/Python/interface/SBSymbolContext.i Sun Feb 5 19:44:54 2012 @@ -79,6 +79,34 @@ bool GetDescription (lldb::SBStream &description); + + + %pythoncode %{ + __swig_getmethods__["module"] = GetModule + __swig_setmethods__["module"] = SetModule + if _newclass: x = property(GetModule, SetModule) + + __swig_getmethods__["compile_unit"] = GetCompileUnit + __swig_setmethods__["compile_unit"] = SetCompileUnit + if _newclass: x = property(GetCompileUnit, SetCompileUnit) + + __swig_getmethods__["function"] = GetFunction + __swig_setmethods__["function"] = SetFunction + if _newclass: x = property(GetFunction, SetFunction) + + __swig_getmethods__["block"] = GetBlock + __swig_setmethods__["block"] = SetBlock + if _newclass: x = property(GetBlock, SetBlock) + + __swig_getmethods__["symbol"] = GetSymbol + __swig_setmethods__["symbol"] = SetSymbol + if _newclass: x = property(GetSymbol, SetSymbol) + + __swig_getmethods__["line_entry"] = GetLineEntry + __swig_setmethods__["line_entry"] = SetLineEntry + if _newclass: x = property(GetLineEntry, SetLineEntry) + %} + }; } // namespace lldb Modified: lldb/trunk/scripts/Python/interface/SBSymbolContextList.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBSymbolContextList.i?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBSymbolContextList.i (original) +++ lldb/trunk/scripts/Python/interface/SBSymbolContextList.i Sun Feb 5 19:44:54 2012 @@ -49,7 +49,92 @@ GetContextAtIndex (uint32_t idx); void + Append (lldb::SBSymbolContext &sc); + + void + Append (lldb::SBSymbolContextList &sc_list); + + bool + GetDescription (lldb::SBStream &description); + + void Clear(); + + %pythoncode %{ + def __len__(self): + return self.GetSize() + + def __getitem__(self, key): + count = len(self) + if type(key) is int: + if key < count: + return self.GetContextAtIndex(key) + else: + raise IndexError + raise TypeError + + def get_module_array(self): + a = [] + for i in range(len(self)): + obj = self.GetContextAtIndex(i).module + if obj: + a.append(obj) + return a + + def get_compile_unit_array(self): + a = [] + for i in range(len(self)): + obj = self.GetContextAtIndex(i).compile_unit + if obj: + a.append(obj) + return a + def get_function_array(self): + a = [] + for i in range(len(self)): + obj = self.GetContextAtIndex(i).function + if obj: + a.append(obj) + return a + def get_block_array(self): + a = [] + for i in range(len(self)): + obj = self.GetContextAtIndex(i).block + if obj: + a.append(obj) + return a + def get_symbol_array(self): + a = [] + for i in range(len(self)): + obj = self.GetContextAtIndex(i).symbol + if obj: + a.append(obj) + return a + def get_line_entry_array(self): + a = [] + for i in range(len(self)): + obj = self.GetContextAtIndex(i).line_entry + if obj: + a.append(obj) + return a + __swig_getmethods__["modules"] = get_module_array + if _newclass: x = property(get_module_array, None) + + __swig_getmethods__["compile_units"] = get_compile_unit_array + if _newclass: x = property(get_compile_unit_array, None) + + __swig_getmethods__["functions"] = get_function_array + if _newclass: x = property(get_function_array, None) + + __swig_getmethods__["blocks"] = get_block_array + if _newclass: x = property(get_block_array, None) + + __swig_getmethods__["line_entries"] = get_line_entry_array + if _newclass: x = property(get_line_entry_array, None) + + __swig_getmethods__["symbols"] = get_symbol_array + if _newclass: x = property(get_symbol_array, None) + %} + }; } // namespace lldb Modified: lldb/trunk/scripts/Python/interface/SBTarget.i URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/scripts/Python/interface/SBTarget.i (original) +++ lldb/trunk/scripts/Python/interface/SBTarget.i Sun Feb 5 19:44:54 2012 @@ -348,23 +348,14 @@ /// C++ methods, or ObjC selectors. /// See FunctionNameType for more details. /// - /// @param[in] append - /// If true, any matches will be appended to \a sc_list, else - /// matches replace the contents of \a sc_list. - /// - /// @param[out] sc_list - /// A symbol context list that gets filled in with all of the - /// matches. - /// /// @return - /// The number of matches added to \a sc_list. + /// A lldb::SBSymbolContextList that gets filled in with all of + /// the symbol contexts for all the matches. //------------------------------------------------------------------ ") FindFunctions; - uint32_t + lldb::SBSymbolContextList FindFunctions (const char *name, - uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits - bool append, - lldb::SBSymbolContextList& sc_list); + uint32_t name_type_mask = lldb::eFunctionNameTypeAny); lldb::SBType FindFirstType (const char* type); Modified: lldb/trunk/scripts/Python/python-extensions.swig URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-extensions.swig (original) +++ lldb/trunk/scripts/Python/python-extensions.swig Sun Feb 5 19:44:54 2012 @@ -280,6 +280,20 @@ return PyString_FromString(""); } } +%extend lldb::SBSymbolContextList { + PyObject *lldb::SBSymbolContextList::__str__ (){ + lldb::SBStream description; + $self->GetDescription (description); + const char *desc = description.GetData(); + size_t desc_len = description.GetSize(); + if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) + --desc_len; + if (desc_len > 0) + return PyString_FromStringAndSize (desc, desc_len); + else + return PyString_FromString(""); + } +} %extend lldb::SBTarget { PyObject *lldb::SBTarget::__str__ (){ lldb::SBStream description; @@ -389,6 +403,13 @@ %pythoncode %{ +class declaration(object): + '''A class that represents a source declaration location with file, line and column.''' + def __init__(self, file, line, col): + self.file = file + self.line = line + self.col = col + class value(object): '''A class designed to wrap lldb.SBValue() objects so the resulting object can be used as a variable would be in code. So if you have a Point structure Modified: lldb/trunk/source/API/SBAddress.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAddress.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBAddress.cpp (original) +++ lldb/trunk/source/API/SBAddress.cpp Sun Feb 5 19:44:54 2012 @@ -352,7 +352,7 @@ { SBBlock sb_block; if (m_opaque_ap.get()) - sb_block.reset(m_opaque_ap->GetAddress().CalculateSymbolContextBlock()); + sb_block.SetPtr(m_opaque_ap->GetAddress().CalculateSymbolContextBlock()); return sb_block; } Modified: lldb/trunk/source/API/SBBlock.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBBlock.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBBlock.cpp (original) +++ lldb/trunk/source/API/SBBlock.cpp Sun Feb 5 19:44:54 2012 @@ -10,11 +10,18 @@ #include "lldb/API/SBBlock.h" #include "lldb/API/SBAddress.h" #include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBFrame.h" #include "lldb/API/SBStream.h" +#include "lldb/API/SBValue.h" #include "lldb/Core/AddressRange.h" +#include "lldb/Core/Log.h" +#include "lldb/Core/ValueObjectVariable.h" #include "lldb/Symbol/Block.h" #include "lldb/Symbol/Function.h" #include "lldb/Symbol/SymbolContext.h" +#include "lldb/Symbol/VariableList.h" +#include "lldb/Target/StackFrame.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; @@ -157,13 +164,13 @@ } lldb_private::Block * -SBBlock::get () +SBBlock::GetPtr () { return m_opaque_ptr; } void -SBBlock::reset (lldb_private::Block *block) +SBBlock::SetPtr (lldb_private::Block *block) { m_opaque_ptr = block; } @@ -245,3 +252,117 @@ return UINT32_MAX; } + +lldb::SBValueList +SBBlock::GetVariables (lldb::SBFrame& frame, + bool arguments, + bool locals, + bool statics, + lldb::DynamicValueType use_dynamic) +{ + Block *block = GetPtr(); + SBValueList value_list; + if (block) + { + StackFrameSP frame_sp(frame.GetFrameSP()); + VariableListSP variable_list_sp (block->GetBlockVariableList (true)); + + if (variable_list_sp) + { + const size_t num_variables = variable_list_sp->GetSize(); + if (num_variables) + { + for (size_t i = 0; i < num_variables; ++i) + { + VariableSP variable_sp (variable_list_sp->GetVariableAtIndex(i)); + if (variable_sp) + { + bool add_variable = false; + switch (variable_sp->GetScope()) + { + case eValueTypeVariableGlobal: + case eValueTypeVariableStatic: + add_variable = statics; + break; + + case eValueTypeVariableArgument: + add_variable = arguments; + break; + + case eValueTypeVariableLocal: + add_variable = locals; + break; + + default: + break; + } + if (add_variable) + { + if (frame_sp) + value_list.Append (frame_sp->GetValueObjectForFrameVariable (variable_sp, use_dynamic)); + } + } + } + } + } + } + return value_list; +} + +lldb::SBValueList +SBBlock::GetVariables (lldb::SBTarget& target, + bool arguments, + bool locals, + bool statics) +{ + Block *block = GetPtr(); + + SBValueList value_list; + if (block) + { + TargetSP target_sp(target.GetSP()); + + VariableListSP variable_list_sp (block->GetBlockVariableList (true)); + + if (variable_list_sp) + { + const size_t num_variables = variable_list_sp->GetSize(); + if (num_variables) + { + for (size_t i = 0; i < num_variables; ++i) + { + VariableSP variable_sp (variable_list_sp->GetVariableAtIndex(i)); + if (variable_sp) + { + bool add_variable = false; + switch (variable_sp->GetScope()) + { + case eValueTypeVariableGlobal: + case eValueTypeVariableStatic: + add_variable = statics; + break; + + case eValueTypeVariableArgument: + add_variable = arguments; + break; + + case eValueTypeVariableLocal: + add_variable = locals; + break; + + default: + break; + } + if (add_variable) + { + if (target_sp) + value_list.Append (ValueObjectVariable::Create (target_sp.get(), variable_sp)); + } + } + } + } + } + } + return value_list; +} + Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Sun Feb 5 19:44:54 2012 @@ -300,12 +300,12 @@ if (frame_sp) { Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.reset (frame_sp->GetSymbolContext (eSymbolContextBlock).block); + sb_block.SetPtr (frame_sp->GetSymbolContext (eSymbolContextBlock).block); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", - frame_sp.get(), sb_block.get()); + frame_sp.get(), sb_block.GetPtr()); return sb_block; } @@ -317,12 +317,12 @@ if (frame_sp) { Mutex::Locker api_locker (frame_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); - sb_block.reset(frame_sp->GetFrameBlock ()); + sb_block.SetPtr(frame_sp->GetFrameBlock ()); } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", - frame_sp.get(), sb_block.get()); + frame_sp.get(), sb_block.GetPtr()); return sb_block; } Modified: lldb/trunk/source/API/SBFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFunction.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBFunction.cpp (original) +++ lldb/trunk/source/API/SBFunction.cpp Sun Feb 5 19:44:54 2012 @@ -192,4 +192,27 @@ return 0; } +SBType +SBFunction::GetType () +{ + SBType sb_type; + if (m_opaque_ptr) + { + Type *function_type = m_opaque_ptr->GetType(); + if (function_type) + sb_type.ref().SetType (function_type->shared_from_this()); + } + return sb_type; +} + +SBBlock +SBFunction::GetBlock () +{ + SBBlock sb_block; + if (m_opaque_ptr) + sb_block.SetPtr (&m_opaque_ptr->GetBlock (true)); + return sb_block; +} + + Modified: lldb/trunk/source/API/SBModule.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBModule.cpp (original) +++ lldb/trunk/source/API/SBModule.cpp Sun Feb 5 19:44:54 2012 @@ -318,25 +318,23 @@ return sb_section; } -uint32_t +lldb::SBSymbolContextList SBModule::FindFunctions (const char *name, - uint32_t name_type_mask, - bool append, - lldb::SBSymbolContextList& sc_list) + uint32_t name_type_mask) { - if (!append) - sc_list.Clear(); + lldb::SBSymbolContextList sb_sc_list; if (name && m_opaque_sp) { + const bool append = true; const bool symbols_ok = true; - return m_opaque_sp->FindFunctions (ConstString(name), - NULL, - name_type_mask, - symbols_ok, - append, - *sc_list); + m_opaque_sp->FindFunctions (ConstString(name), + NULL, + name_type_mask, + symbols_ok, + append, + *sb_sc_list); } - return 0; + return sb_sc_list; } Modified: lldb/trunk/source/API/SBSymbolContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbolContext.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBSymbolContext.cpp (original) +++ lldb/trunk/source/API/SBSymbolContext.cpp Sun Feb 5 19:44:54 2012 @@ -199,7 +199,7 @@ void SBSymbolContext::SetBlock (lldb::SBBlock block) { - ref().block = block.get(); + ref().block = block.GetPtr(); } void Modified: lldb/trunk/source/API/SBSymbolContextList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbolContextList.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBSymbolContextList.cpp (original) +++ lldb/trunk/source/API/SBSymbolContextList.cpp Sun Feb 5 19:44:54 2012 @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBSymbolContextList.h" +#include "lldb/API/SBStream.h" #include "lldb/Symbol/SymbolContext.h" using namespace lldb; @@ -67,6 +68,20 @@ m_opaque_ap->Clear(); } +void +SBSymbolContextList::Append(SBSymbolContext &sc) +{ + if (sc.IsValid() && m_opaque_ap.get()) + m_opaque_ap->Append(*sc); +} + +void +SBSymbolContextList::Append(SBSymbolContextList &sc_list) +{ + if (sc_list.IsValid() && m_opaque_ap.get()) + m_opaque_ap->Append(*sc_list); +} + bool SBSymbolContextList::IsValid () const @@ -90,6 +105,13 @@ return *m_opaque_ap.get(); } - +bool +SBSymbolContextList::GetDescription (lldb::SBStream &description) +{ + Stream &strm = description.ref(); + if (m_opaque_ap.get()) + m_opaque_ap->GetDescription (&strm, lldb::eDescriptionLevelFull, NULL); + return true; +} Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Sun Feb 5 19:44:54 2012 @@ -1252,28 +1252,25 @@ return true; } -uint32_t -SBTarget::FindFunctions (const char *name, - uint32_t name_type_mask, - bool append, - lldb::SBSymbolContextList& sc_list) +lldb::SBSymbolContextList +SBTarget::FindFunctions (const char *name, uint32_t name_type_mask) { - if (!append) - sc_list.Clear(); + lldb::SBSymbolContextList sb_sc_list; if (name && name[0]) { TargetSP target_sp(GetSP()); if (target_sp) { const bool symbols_ok = true; - return target_sp->GetImages().FindFunctions (ConstString(name), - name_type_mask, - symbols_ok, - append, - *sc_list); + const bool append = true; + target_sp->GetImages().FindFunctions (ConstString(name), + name_type_mask, + symbols_ok, + append, + *sb_sc_list); } } - return 0; + return sb_sc_list; } lldb::SBType Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sun Feb 5 19:44:54 2012 @@ -4158,21 +4158,21 @@ const char *name2 = decl_ctx_die2->GetName(this, cu2); // If the string was from a DW_FORM_strp, then the pointer will often // be the same! - if (name1 != name2) + if (name1 == name2) + continue; + + // Name pointers are not equal, so only compare the strings + // if both are not NULL. + if (name1 && name2) { - // Name pointers are not equal, so only compare the strings - // if both are not NULL. - if (name1 && name2) - { - // If the strings don't compare, we are done... - if (strcmp(name1, name2) != 0) - return false; - } - else if (name1 || name2) - { - // One name was NULL while the other wasn't + // If the strings don't compare, we are done... + if (strcmp(name1, name2) != 0) return false; - } + } + else + { + // One name was NULL while the other wasn't + return false; } } // We made it through all of the checks and the declaration contexts Modified: lldb/trunk/source/Symbol/SymbolContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/source/Symbol/SymbolContext.cpp (original) +++ lldb/trunk/source/Symbol/SymbolContext.cpp Sun Feb 5 19:44:54 2012 @@ -905,6 +905,28 @@ m_symbol_contexts.push_back(sc); } +void +SymbolContextList::Append (const SymbolContextList& sc_list) +{ + collection::const_iterator pos, end = sc_list.m_symbol_contexts.end(); + for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos) + m_symbol_contexts.push_back (*pos); +} + + +uint32_t +SymbolContextList::AppendIfUnique (const SymbolContextList& sc_list, bool merge_symbol_into_function) +{ + uint32_t unique_sc_add_count = 0; + collection::const_iterator pos, end = sc_list.m_symbol_contexts.end(); + for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos) + { + if (AppendIfUnique (*pos, merge_symbol_into_function)) + ++unique_sc_add_count; + } + return unique_sc_add_count; +} + bool SymbolContextList::AppendIfUnique (const SymbolContext& sc, bool merge_symbol_into_function) { @@ -1013,6 +1035,16 @@ return match_count; } +void +SymbolContextList::GetDescription(Stream *s, + lldb::DescriptionLevel level, + Target *target) const +{ + const uint32_t size = m_symbol_contexts.size(); + for (uint32_t idx = 0; idxGetClangAST(), type_sp->GetClangFullType()); + m_type_sp = type_sp; + } + else + { + m_clang_ast_type.Clear(); + m_type_sp.reset(); + } +} + TypeImpl& TypeImpl::operator = (const TypeImpl& rhs) { Modified: lldb/trunk/test/python_api/default-constructor/sb_module.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_module.py?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/test/python_api/default-constructor/sb_module.py (original) +++ lldb/trunk/test/python_api/default-constructor/sb_module.py Sun Feb 5 19:44:54 2012 @@ -15,7 +15,8 @@ obj.GetDescription(lldb.SBStream()) obj.GetNumSymbols() obj.GetSymbolAtIndex(sys.maxint) - obj.FindFunctions("my_func", 0xffffffff, True, lldb.SBSymbolContextList()) + sc_list = obj.FindFunctions("my_func") + sc_list = obj.FindFunctions("my_func", lldb.eFunctionNameTypeAny) obj.FindGlobalVariables(lldb.SBTarget(), "my_global_var", 1) for section in obj.section_iter(): print section Modified: lldb/trunk/test/python_api/default-constructor/sb_target.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/default-constructor/sb_target.py?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/test/python_api/default-constructor/sb_target.py (original) +++ lldb/trunk/test/python_api/default-constructor/sb_target.py Sun Feb 5 19:44:54 2012 @@ -20,8 +20,8 @@ obj.GetDebugger() filespec = lldb.SBFileSpec() obj.FindModule(filespec) - contextlist = lldb.SBSymbolContextList() - obj.FindFunctions("the_func", 0xff, True, contextlist) + sc_list = obj.FindFunctions("the_func") + sc_list = obj.FindFunctions("the_func", lldb.eFunctionNameTypeAny) obj.FindFirstType("dont_care") obj.FindTypes("dont_care") obj.FindFirstType(None) Modified: lldb/trunk/test/python_api/module_section/TestModuleAndSection.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/module_section/TestModuleAndSection.py?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/test/python_api/module_section/TestModuleAndSection.py (original) +++ lldb/trunk/test/python_api/module_section/TestModuleAndSection.py Sun Feb 5 19:44:54 2012 @@ -87,7 +87,7 @@ exe_module.FindFirstType(None) exe_module.FindTypes(None) exe_module.FindGlobalVariables(target, None, 1) - exe_module.FindFunctions(None, 0, True, lldb.SBSymbolContextList()) + exe_module.FindFunctions(None, 0) exe_module.FindSection(None) # Get the section at index 1. Modified: lldb/trunk/test/python_api/target/TestTargetAPI.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/target/TestTargetAPI.py?rev=149853&r1=149852&r2=149853&view=diff ============================================================================== --- lldb/trunk/test/python_api/target/TestTargetAPI.py (original) +++ lldb/trunk/test/python_api/target/TestTargetAPI.py Sun Feb 5 19:44:54 2012 @@ -152,9 +152,8 @@ target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - list = lldb.SBSymbolContextList() - num = target.FindFunctions('c', lldb.eFunctionNameTypeAuto, False, list) - self.assertTrue(num == 1 and list.GetSize() == 1) + list = target.FindFunctions('c', lldb.eFunctionNameTypeAuto) + self.assertTrue(list.GetSize() == 1) for sc in list: self.assertTrue(sc.GetModule().GetFileSpec().GetFilename() == exe_name)