llvm-project/lldb/source/Target/ExecutionContext.cpp

224 lines
4.6 KiB
C++
Raw Normal View History

//===-- ExecutionContext.cpp ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
using namespace lldb_private;
ExecutionContext::ExecutionContext() :
m_target_sp (),
m_process_sp (),
m_thread_sp (),
m_frame_sp ()
{
}
ExecutionContext::ExecutionContext (const ExecutionContext &rhs) :
m_target_sp (rhs.m_target_sp),
m_process_sp(rhs.m_process_sp),
m_thread_sp (rhs.m_thread_sp),
m_frame_sp (rhs.m_frame_sp)
{
}
ExecutionContext &
ExecutionContext::operator =(const ExecutionContext &rhs)
{
if (this != &rhs)
{
m_target_sp = rhs.m_target_sp;
m_process_sp = rhs.m_process_sp;
m_thread_sp = rhs.m_thread_sp;
m_frame_sp = rhs.m_frame_sp;
}
return *this;
}
ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) :
m_target_sp (t),
m_process_sp (),
m_thread_sp (),
m_frame_sp ()
{
if (t && fill_current_process_thread_frame)
{
m_process_sp = t->GetProcessSP();
if (m_process_sp)
{
m_thread_sp = m_process_sp->GetThreadList().GetSelectedThread();
if (m_thread_sp)
m_frame_sp = m_thread_sp->GetSelectedFrame().get();
}
}
}
ExecutionContext::ExecutionContext(Process* process, Thread *thread, StackFrame *frame) :
m_target_sp (process ? &process->GetTarget() : NULL),
m_process_sp (process),
m_thread_sp (thread),
m_frame_sp (frame)
{
}
ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr)
{
if (exe_scope_ptr)
There are now to new "settings set" variables that live in each debugger instance: settings set frame-format <string> settings set thread-format <string> This allows users to control the information that is seen when dumping threads and frames. The default values are set such that they do what they used to do prior to changing over the the user defined formats. This allows users with terminals that can display color to make different items different colors using the escape control codes. A few alias examples that will colorize your thread and frame prompts are: settings set frame-format 'frame #${frame.index}: \033[0;33m${frame.pc}\033[0m{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{ \033[0;35mat \033[1;35m${line.file.basename}:${line.number}}\033[0m\n' settings set thread-format 'thread #${thread.index}: \033[1;33mtid\033[0;33m = ${thread.id}\033[0m{, \033[0;33m${frame.pc}\033[0m}{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{, \033[1;35mstop reason\033[0;35m = ${thread.stop-reason}\033[0m}{, \033[1;36mname = \033[0;36m${thread.name}\033[0m}{, \033[1;32mqueue = \033[0;32m${thread.queue}}\033[0m\n' A quick web search for "colorize terminal output" should allow you to see what you can do to make your output look like you want it. The "settings set" commands above can of course be added to your ~/.lldbinit file for permanent use. Changed the pure virtual void ExecutionContextScope::Calculate (ExecutionContext&); To: void ExecutionContextScope::CalculateExecutionContext (ExecutionContext&); I did this because this is a class that anything in the execution context heirarchy inherits from and "target->Calculate (exe_ctx)" didn't always tell you what it was really trying to do unless you look at the parameter. llvm-svn: 115485
2010-10-04 09:05:56 +08:00
exe_scope_ptr->CalculateExecutionContext (*this);
else
{
m_target_sp.reset();
m_process_sp.reset();
m_thread_sp.reset();
m_frame_sp.reset();
}
}
ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref)
{
There are now to new "settings set" variables that live in each debugger instance: settings set frame-format <string> settings set thread-format <string> This allows users to control the information that is seen when dumping threads and frames. The default values are set such that they do what they used to do prior to changing over the the user defined formats. This allows users with terminals that can display color to make different items different colors using the escape control codes. A few alias examples that will colorize your thread and frame prompts are: settings set frame-format 'frame #${frame.index}: \033[0;33m${frame.pc}\033[0m{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{ \033[0;35mat \033[1;35m${line.file.basename}:${line.number}}\033[0m\n' settings set thread-format 'thread #${thread.index}: \033[1;33mtid\033[0;33m = ${thread.id}\033[0m{, \033[0;33m${frame.pc}\033[0m}{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{, \033[1;35mstop reason\033[0;35m = ${thread.stop-reason}\033[0m}{, \033[1;36mname = \033[0;36m${thread.name}\033[0m}{, \033[1;32mqueue = \033[0;32m${thread.queue}}\033[0m\n' A quick web search for "colorize terminal output" should allow you to see what you can do to make your output look like you want it. The "settings set" commands above can of course be added to your ~/.lldbinit file for permanent use. Changed the pure virtual void ExecutionContextScope::Calculate (ExecutionContext&); To: void ExecutionContextScope::CalculateExecutionContext (ExecutionContext&); I did this because this is a class that anything in the execution context heirarchy inherits from and "target->Calculate (exe_ctx)" didn't always tell you what it was really trying to do unless you look at the parameter. llvm-svn: 115485
2010-10-04 09:05:56 +08:00
exe_scope_ref.CalculateExecutionContext (*this);
}
void
ExecutionContext::Clear()
{
m_target_sp.reset();
m_process_sp.reset();
m_thread_sp.reset();
m_frame_sp.reset();
}
ExecutionContext::~ExecutionContext()
{
}
RegisterContext *
ExecutionContext::GetRegisterContext () const
{
if (m_frame_sp)
return m_frame_sp->GetRegisterContext().get();
else if (m_thread_sp)
return m_thread_sp->GetRegisterContext().get();
return NULL;
}
Target *
ExecutionContext::GetTargetPtr () const
{
if (m_target_sp)
return m_target_sp.get();
if (m_process_sp)
return &m_process_sp->GetTarget();
return NULL;
}
Process *
ExecutionContext::GetProcessPtr () const
{
if (m_process_sp)
return m_process_sp.get();
if (m_target_sp)
return m_target_sp->GetProcessSP().get();
return NULL;
}
ExecutionContextScope *
ExecutionContext::GetBestExecutionContextScope () const
{
if (m_frame_sp)
return m_frame_sp.get();
if (m_thread_sp)
return m_thread_sp.get();
if (m_process_sp)
return m_process_sp.get();
return m_target_sp.get();
}
Target &
ExecutionContext::GetTargetRef () const
{
assert (m_target_sp.get());
return *m_target_sp;
}
Process &
ExecutionContext::GetProcessRef () const
{
assert (m_process_sp.get());
return *m_process_sp;
}
Thread &
ExecutionContext::GetThreadRef () const
{
assert (m_thread_sp.get());
return *m_thread_sp;
}
StackFrame &
ExecutionContext::GetFrameRef () const
{
assert (m_frame_sp.get());
return *m_frame_sp;
}
void
ExecutionContext::SetTargetSP (const lldb::TargetSP &target_sp)
{
m_target_sp = target_sp;
}
void
ExecutionContext::SetProcessSP (const lldb::ProcessSP &process_sp)
{
m_process_sp = process_sp;
}
void
ExecutionContext::SetThreadSP (const lldb::ThreadSP &thread_sp)
{
m_thread_sp = thread_sp;
}
void
ExecutionContext::SetFrameSP (const lldb::StackFrameSP &frame_sp)
{
m_frame_sp = frame_sp;
}
void
ExecutionContext::SetTargetPtr (Target* target)
{
m_target_sp = target;
}
void
ExecutionContext::SetProcessPtr (Process *process)
{
m_process_sp = process;
}
void
ExecutionContext::SetThreadPtr (Thread *thread)
{
m_thread_sp = thread;
}
void
ExecutionContext::SetFramePtr (StackFrame *frame)
{
m_frame_sp = frame;
}