diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/API/SBProcess.cpp | 14 | ||||
-rw-r--r-- | lldb/source/API/SBUnixSignals.cpp | 199 |
3 files changed, 214 insertions, 0 deletions
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index 63adb68e486..b903b4e7aae 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -51,4 +51,5 @@ add_lldb_library(lldbAPI SBValue.cpp SBValueList.cpp SBWatchpoint.cpp + SBUnixSignals.cpp ) diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index bb5b989df6c..41efd86177d 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -40,6 +40,7 @@ #include "lldb/API/SBThread.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBStringList.h" +#include "lldb/API/SBUnixSignals.h" using namespace lldb; using namespace lldb_private; @@ -893,6 +894,19 @@ SBProcess::Signal (int signo) return sb_error; } +SBUnixSignals +SBProcess::GetUnixSignals() +{ + SBUnixSignals sb_unix_signals; + ProcessSP process_sp(GetSP()); + if (process_sp) + { + sb_unix_signals.SetSP(process_sp); + } + + return sb_unix_signals; +} + void SBProcess::SendAsyncInterrupt () { diff --git a/lldb/source/API/SBUnixSignals.cpp b/lldb/source/API/SBUnixSignals.cpp new file mode 100644 index 00000000000..ca321d82fd6 --- /dev/null +++ b/lldb/source/API/SBUnixSignals.cpp @@ -0,0 +1,199 @@ +//===-- SBUnixSignals.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/lldb-defines.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/UnixSignals.h" +#include "lldb/Core/Log.h" + +#include "lldb/API/SBUnixSignals.h" + +using namespace lldb; +using namespace lldb_private; + +SBUnixSignals::SBUnixSignals () +{} + +SBUnixSignals::SBUnixSignals (const SBUnixSignals &rhs) : + m_opaque_wp(rhs.m_opaque_wp) +{ +} + +SBUnixSignals::SBUnixSignals (ProcessSP &process_sp) : + m_opaque_wp(process_sp) +{ +} + +const SBUnixSignals& +SBUnixSignals::operator = (const SBUnixSignals& rhs) +{ + if (this != &rhs) + m_opaque_wp = rhs.m_opaque_wp; + return *this; +} + +SBUnixSignals::~SBUnixSignals() +{ +} + +ProcessSP +SBUnixSignals::GetSP() const +{ + return m_opaque_wp.lock(); +} + +void +SBUnixSignals::SetSP (const ProcessSP &process_sp) +{ + m_opaque_wp = process_sp; +} + +void +SBUnixSignals::Clear () +{ + m_opaque_wp.reset(); +} + +bool +SBUnixSignals::IsValid() const +{ + return (bool) GetSP(); +} + +const char * +SBUnixSignals::GetSignalAsCString (int32_t signo) const +{ + ProcessSP process_sp(GetSP()); + if (process_sp) return process_sp->GetUnixSignals().GetSignalAsCString(signo); + return NULL; +} + +int32_t +SBUnixSignals::GetSignalNumberFromName (const char *name) const +{ + ProcessSP process_sp(GetSP()); + if (process_sp) return process_sp->GetUnixSignals().GetSignalNumberFromName(name); + return -1; +} + +bool +SBUnixSignals::GetShouldSuppress (int32_t signo) const +{ + ProcessSP process_sp(GetSP()); + if (process_sp) return process_sp->GetUnixSignals().GetShouldSuppress(signo); + return false; +} + +bool +SBUnixSignals::SetShouldSuppress (int32_t signo, bool value) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + ProcessSP process_sp(GetSP()); + + if (log) + { + log->Printf ("SBUnixSignals(%p)::SetShouldSuppress (signo=%d, value=%d)", + static_cast<void*>(process_sp.get()), + signo, + value); + } + + if (process_sp) return process_sp->GetUnixSignals().SetShouldSuppress(signo, value); + return false; +} + +bool +SBUnixSignals::GetShouldStop (int32_t signo) const +{ + ProcessSP process_sp(GetSP()); + if (process_sp) return process_sp->GetUnixSignals().GetShouldStop(signo); + return false; +} + +bool +SBUnixSignals::SetShouldStop (int32_t signo, bool value) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + ProcessSP process_sp(GetSP()); + + if (log) + { + log->Printf ("SBUnixSignals(%p)::SetShouldStop (signo=%d, value=%d)", + static_cast<void*>(process_sp.get()), + signo, + value); + } + + if (process_sp) return process_sp->GetUnixSignals().SetShouldStop(signo, value); + return false; +} + +bool +SBUnixSignals::GetShouldNotify (int32_t signo) const +{ + ProcessSP process_sp(GetSP()); + if (process_sp) return process_sp->GetUnixSignals().GetShouldNotify(signo); + return false; +} + +bool +SBUnixSignals::SetShouldNotify (int32_t signo, bool value) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + ProcessSP process_sp(GetSP()); + + if (log) + { + log->Printf ("SBUnixSignals(%p)::SetShouldNotify (signo=%d, value=%d)", + static_cast<void*>(process_sp.get()), + signo, + value); + } + + if (process_sp) return process_sp->GetUnixSignals().SetShouldNotify(signo, value); + return false; +} + +int32_t +SBUnixSignals::GetNumSignals () const +{ + if (auto process_sp = GetSP()) + { + // only valid while we hold process_sp + UnixSignals *unix_signals_ptr = &process_sp->GetUnixSignals(); + int32_t num_signals = 0; + for (int32_t signo = unix_signals_ptr->GetFirstSignalNumber(); + signo != LLDB_INVALID_SIGNAL_NUMBER; + signo = unix_signals_ptr->GetNextSignalNumber(signo)) + { + num_signals++; + } + return num_signals; + } + return LLDB_INVALID_SIGNAL_NUMBER; +} + +int32_t +SBUnixSignals::GetSignalAtIndex (int32_t index) const +{ + if (auto process_sp = GetSP()) + { + // only valid while we hold process_sp + UnixSignals *unix_signals_ptr = &process_sp->GetUnixSignals(); + int32_t idx = 0; + for (int32_t signo = unix_signals_ptr->GetFirstSignalNumber(); + signo != LLDB_INVALID_SIGNAL_NUMBER; + signo = unix_signals_ptr->GetNextSignalNumber(signo)) + { + if (index == idx) return signo; + idx++; + } + } + return LLDB_INVALID_SIGNAL_NUMBER; +} |