[lldb-dev] Ignoring Signals via the API
jingham at apple.com
jingham at apple.com
Fri Jun 28 08:44:40 PDT 2013
That look great. Would I be too much of a pain if I were to ask for a test case?
Jim
On Jun 28, 2013, at 2:35 AM, Russell Harmon <russ at eatnumber1.com> wrote:
> Done. One comment though, I was thinking it'd be good to cache the list of signals in the SBUnixSignals object which both GetNumSignals and GetSignalAtIndex generates. Otherwise, the python enumerator is a O(n^2) operation. Probably not a real issue as there aren't very many signals, but it's just a nit.
> --
> Russell Harmon
>
> From 66b8c02da8a274f58288c2a1037eaff1a94f7620 Mon Sep 17 00:00:00 2001
> From: Russell Harmon <russ at eatnumber1.com>
> Date: Tue, 25 Jun 2013 01:02:31 -0700
> Subject: [PATCH] Add the ability to control the signal disposition via the
> API.
>
> ---
> include/lldb/API/LLDB.h | 1 +
> include/lldb/API/SBDefines.h | 1 +
> include/lldb/API/SBProcess.h | 3 +
> include/lldb/API/SBUnixSignals.h | 84 ++++++++++++++++
> include/lldb/lldb-defines.h | 4 +
> include/lldb/lldb-forward.h | 1 +
> scripts/Python/build-swig-Python.sh | 6 +-
> scripts/Python/interface/SBProcess.i | 3 +
> scripts/Python/interface/SBUnixSignals.i | 74 ++++++++++++++
> scripts/lldb.swig | 5 +
> source/API/CMakeLists.txt | 1 +
> source/API/SBProcess.cpp | 14 +++
> source/API/SBUnixSignals.cpp | 161 +++++++++++++++++++++++++++++++
> 13 files changed, 356 insertions(+), 2 deletions(-)
> create mode 100644 include/lldb/API/SBUnixSignals.h
> create mode 100644 scripts/Python/interface/SBUnixSignals.i
> create mode 100644 source/API/SBUnixSignals.cpp
>
> diff --git a/include/lldb/API/LLDB.h b/include/lldb/API/LLDB.h
> index 93bc3bc..4db60b0 100644
> --- a/include/lldb/API/LLDB.h
> +++ b/include/lldb/API/LLDB.h
> @@ -50,5 +50,6 @@
> #include "lldb/API/SBType.h"
> #include "lldb/API/SBValue.h"
> #include "lldb/API/SBValueList.h"
> +#include "lldb/API/SBUnixSignals.h"
>
> #endif // LLDB_LLDB_h_
> diff --git a/include/lldb/API/SBDefines.h b/include/lldb/API/SBDefines.h
> index 2388c36..02742d3 100644
> --- a/include/lldb/API/SBDefines.h
> +++ b/include/lldb/API/SBDefines.h
> @@ -76,6 +76,7 @@ class SBTypeList;
> class SBValue;
> class SBValueList;
> class SBWatchpoint;
> +class SBUnixSignals;
>
> }
>
> diff --git a/include/lldb/API/SBProcess.h b/include/lldb/API/SBProcess.h
> index 784f362..a1e7353 100644
> --- a/include/lldb/API/SBProcess.h
> +++ b/include/lldb/API/SBProcess.h
> @@ -211,6 +211,9 @@ public:
> lldb::SBError
> Signal (int signal);
>
> + lldb::SBUnixSignals
> + GetUnixSignals();
> +
> void
> SendAsyncInterrupt();
>
> diff --git a/include/lldb/API/SBUnixSignals.h b/include/lldb/API/SBUnixSignals.h
> new file mode 100644
> index 0000000..d95453a
> --- /dev/null
> +++ b/include/lldb/API/SBUnixSignals.h
> @@ -0,0 +1,84 @@
> +//===-- SBUnixSignals.h -----------------------------------------------*- C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef LLDB_SBUnixSignals_h_
> +#define LLDB_SBUnixSignals_h_
> +
> +#include "lldb/API/SBDefines.h"
> +
> +namespace lldb {
> +
> +class SBUnixSignals {
> +public:
> + SBUnixSignals ();
> +
> + SBUnixSignals (const lldb::SBUnixSignals &rhs);
> +
> + ~SBUnixSignals();
> +
> + const SBUnixSignals &
> + operator =(const lldb::SBUnixSignals &rhs);
> +
> + void
> + Clear ();
> +
> + bool
> + IsValid () const;
> +
> + const char *
> + GetSignalAsCString (int32_t signo) const;
> +
> + int32_t
> + GetSignalNumberFromName (const char *name) const;
> +
> + bool
> + GetShouldSuppress (int32_t signo) const;
> +
> + bool
> + SetShouldSuppress (int32_t signo,
> + bool value);
> +
> + bool
> + GetShouldStop (int32_t signo) const;
> +
> + bool
> + SetShouldStop (int32_t signo,
> + bool value);
> +
> + bool
> + GetShouldNotify (int32_t signo) const;
> +
> + bool
> + SetShouldNotify (int32_t signo, bool value);
> +
> + int32_t
> + GetNumSignals () const;
> +
> + int32_t
> + GetSignalAtIndex (int32_t index) const;
> +
> +protected:
> + friend class SBProcess;
> +
> + SBUnixSignals (lldb_private::UnixSignals *unix_signals_ptr);
> +
> + lldb_private::UnixSignals *
> + GetPtr() const;
> +
> + void
> + SetPtr (lldb_private::UnixSignals *unix_signals_ptr);
> +
> +private:
> + lldb_private::UnixSignals *m_opaque_ptr;
> +};
> +
> +
> +} // namespace lldb
> +
> +#endif // LLDB_SBUnixSignals_h_
> diff --git a/include/lldb/lldb-defines.h b/include/lldb/lldb-defines.h
> index 3318aa1..a42ba3c 100644
> --- a/include/lldb/lldb-defines.h
> +++ b/include/lldb/lldb-defines.h
> @@ -12,6 +12,10 @@
>
> #include "lldb/lldb-types.h"
>
> +#if !defined(INT32_MAX)
> + #define INT32_MAX 2147483647
> +#endif
> +
> #if !defined(UINT32_MAX)
> #define UINT32_MAX 4294967295U
> #endif
> diff --git a/include/lldb/lldb-forward.h b/include/lldb/lldb-forward.h
> index 84af8b6..077d537 100644
> --- a/include/lldb/lldb-forward.h
> +++ b/include/lldb/lldb-forward.h
> @@ -232,6 +232,7 @@ class TypeListImpl;
> class TypeMemberImpl;
> class TypeNameSpecifierImpl;
> class UUID;
> +class UnixSignals;
> class Unwind;
> class UnwindAssembly;
> class UnwindPlan;
> diff --git a/scripts/Python/build-swig-Python.sh b/scripts/Python/build-swig-Python.sh
> index 96c4b2b..4a111da 100755
> --- a/scripts/Python/build-swig-Python.sh
> +++ b/scripts/Python/build-swig-Python.sh
> @@ -123,7 +123,8 @@ HEADER_FILES="${SRC_ROOT}/include/lldb/lldb.h"\
> " ${SRC_ROOT}/include/lldb/API/SBTypeSynthetic.h"\
> " ${SRC_ROOT}/include/lldb/API/SBValue.h"\
> " ${SRC_ROOT}/include/lldb/API/SBValueList.h"\
> -" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"
> +" ${SRC_ROOT}/include/lldb/API/SBWatchpoint.h"\
> +" ${SRC_ROOT}/include/lldb/API/SBUnixSignals.h"
>
> INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\
> " ${SRC_ROOT}/scripts/Python/interface/SBBlock.i"\
> @@ -167,7 +168,8 @@ INTERFACE_FILES="${SRC_ROOT}/scripts/Python/interface/SBAddress.i"\
> " ${SRC_ROOT}/scripts/Python/interface/SBTypeSynthetic.i"\
> " ${SRC_ROOT}/scripts/Python/interface/SBValue.i"\
> " ${SRC_ROOT}/scripts/Python/interface/SBValueList.i"\
> -" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"
> +" ${SRC_ROOT}/scripts/Python/interface/SBWatchpoint.i"\
> +" ${SRC_ROOT}/scripts/Python/interface/SBUnixSignals.i"
>
> if [ $Debug -eq 1 ]
> then
> diff --git a/scripts/Python/interface/SBProcess.i b/scripts/Python/interface/SBProcess.i
> index 6f22d9a..7a03ac7 100644
> --- a/scripts/Python/interface/SBProcess.i
> +++ b/scripts/Python/interface/SBProcess.i
> @@ -231,6 +231,9 @@ public:
> lldb::SBError
> Signal (int signal);
>
> + lldb::SBUnixSignals
> + GetUnixSignals();
> +
> %feature("docstring", "
> Returns a stop id that will increase every time the process executes. If
> include_expression_stops is true, then stops caused by expression evaluation
> diff --git a/scripts/Python/interface/SBUnixSignals.i b/scripts/Python/interface/SBUnixSignals.i
> new file mode 100644
> index 0000000..2bd537a
> --- /dev/null
> +++ b/scripts/Python/interface/SBUnixSignals.i
> @@ -0,0 +1,74 @@
> +//===-- SWIG Interface for SBProcess ----------------------------*- C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +namespace lldb {
> +
> +%feature("docstring",
> +"Allows you to manipulate LLDB's signal disposition"
> +) SBUnixSignals;
> +class SBUnixSignals
> +{
> +public:
> + SBUnixSignals ();
> +
> + SBUnixSignals (const lldb::SBUnixSignals &rhs);
> +
> + ~SBUnixSignals();
> +
> + void
> + Clear ();
> +
> + bool
> + IsValid () const;
> +
> + const char *
> + GetSignalAsCString (int32_t signo) const;
> +
> + int32_t
> + GetSignalNumberFromName (const char *name) const;
> +
> + bool
> + GetShouldSuppress (int32_t signo) const;
> +
> + bool
> + SetShouldSuppress (int32_t signo,
> + bool value);
> +
> + bool
> + GetShouldStop (int32_t signo) const;
> +
> + bool
> + SetShouldStop (int32_t signo,
> + bool value);
> +
> + bool
> + GetShouldNotify (int32_t signo) const;
> +
> + bool
> + SetShouldNotify (int32_t signo, bool value);
> +
> + int32_t
> + GetNumSignals () const;
> +
> + int32_t
> + GetSignalAtIndex (int32_t index) const;
> +
> + %pythoncode %{
> + def get_unix_signals_list(self):
> + signals = []
> + for idx in range(0, self.GetNumSignals()):
> + signals.append(self.GetSignalAtIndex(sig))
> + return signals
> +
> + __swig_getmethods__["signals"] = get_unix_signals_list
> + if _newclass: threads = property(get_unix_signals_list, None, doc='''A read only property that returns a list() of valid signal numbers for this platform.''')
> + %}
> +};
> +
> +} // namespace lldb
> diff --git a/scripts/lldb.swig b/scripts/lldb.swig
> index b813f51..0a9a8ca 100644
> --- a/scripts/lldb.swig
> +++ b/scripts/lldb.swig
> @@ -98,6 +98,7 @@ import os
> #include "lldb/API/SBValue.h"
> #include "lldb/API/SBValueList.h"
> #include "lldb/API/SBWatchpoint.h"
> +#include "lldb/API/SBUnixSignals.h"
>
> #include "../scripts/Python/python-swigsafecast.swig"
>
> @@ -105,6 +106,9 @@ import os
>
> /* Various liblldb typedefs that SWIG needs to know about. */
> #define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */
> +/* The ISO C99 standard specifies that in C++ implementations limit macros such
> + as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */
> +#define __STDC_LIMIT_MACROS
> %include "stdint.i"
> %include "lldb/lldb-defines.h"
> %include "lldb/lldb-enumerations.h"
> @@ -161,6 +165,7 @@ import os
> %include "./Python/interface/SBValue.i"
> %include "./Python/interface/SBValueList.i"
> %include "./Python/interface/SBWatchpoint.i"
> +%include "./Python/interface/SBUnixSignals.i"
>
> %include "./Python/python-extensions.swig"
>
> diff --git a/source/API/CMakeLists.txt b/source/API/CMakeLists.txt
> index 3580b74..937a4c2 100644
> --- a/source/API/CMakeLists.txt
> +++ b/source/API/CMakeLists.txt
> @@ -47,4 +47,5 @@ add_lldb_library(lldbAPI
> SBValue.cpp
> SBValueList.cpp
> SBWatchpoint.cpp
> + SBUnixSignals.cpp
> )
> diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp
> index d41ad61..3215fe5 100644
> --- a/source/API/SBProcess.cpp
> +++ b/source/API/SBProcess.cpp
> @@ -36,6 +36,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;
> @@ -833,6 +834,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.SetPtr(&process_sp->GetUnixSignals());
> + }
> +
> + return sb_unix_signals;
> +}
> +
> void
> SBProcess::SendAsyncInterrupt ()
> {
> diff --git a/source/API/SBUnixSignals.cpp b/source/API/SBUnixSignals.cpp
> new file mode 100644
> index 0000000..5963317
> --- /dev/null
> +++ b/source/API/SBUnixSignals.cpp
> @@ -0,0 +1,161 @@
> +//===-- 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/UnixSignals.h"
> +
> +#include "lldb/API/SBUnixSignals.h"
> +
> +using namespace lldb;
> +using namespace lldb_private;
> +
> +SBUnixSignals::SBUnixSignals () :
> + m_opaque_ptr(NULL)
> +{
> +}
> +
> +SBUnixSignals::SBUnixSignals (const SBUnixSignals &rhs) :
> + m_opaque_ptr(rhs.m_opaque_ptr)
> +{
> +}
> +
> +SBUnixSignals::SBUnixSignals (UnixSignals *unix_signals_ptr) :
> + m_opaque_ptr(unix_signals_ptr)
> +{
> +}
> +
> +const SBUnixSignals&
> +SBUnixSignals::operator = (const SBUnixSignals& rhs)
> +{
> + if (this != &rhs)
> + m_opaque_ptr = rhs.m_opaque_ptr;
> + return *this;
> +}
> +
> +SBUnixSignals::~SBUnixSignals()
> +{
> +}
> +
> +UnixSignals *
> +SBUnixSignals::GetPtr() const
> +{
> + return m_opaque_ptr;
> +}
> +
> +void
> +SBUnixSignals::SetPtr (UnixSignals *unix_signals_ptr)
> +{
> + m_opaque_ptr = unix_signals_ptr;
> +}
> +
> +void
> +SBUnixSignals::Clear ()
> +{
> + m_opaque_ptr = NULL;
> +}
> +
> +bool
> +SBUnixSignals::IsValid() const
> +{
> + return m_opaque_ptr != NULL;
> +}
> +
> +const char *
> +SBUnixSignals::GetSignalAsCString (int32_t signo) const
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->GetSignalAsCString(signo);
> + return NULL;
> +}
> +
> +int32_t
> +SBUnixSignals::GetSignalNumberFromName (const char *name) const
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->GetSignalNumberFromName(name);
> + return -1;
> +}
> +
> +bool
> +SBUnixSignals::GetShouldSuppress (int32_t signo) const
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->GetShouldSuppress(signo);
> + return false;
> +}
> +
> +bool
> +SBUnixSignals::SetShouldSuppress (int32_t signo, bool value)
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->SetShouldSuppress(signo, value);
> + return false;
> +}
> +
> +bool
> +SBUnixSignals::GetShouldStop (int32_t signo) const
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->GetShouldStop(signo);
> + return false;
> +}
> +
> +bool
> +SBUnixSignals::SetShouldStop (int32_t signo, bool value)
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->SetShouldStop(signo, value);
> + return false;
> +}
> +
> +bool
> +SBUnixSignals::GetShouldNotify (int32_t signo) const
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->GetShouldNotify(signo);
> + return false;
> +}
> +
> +bool
> +SBUnixSignals::SetShouldNotify (int32_t signo, bool value)
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->SetShouldNotify(signo, value);
> + return false;
> +}
> +
> +int32_t
> +SBUnixSignals::GetNumSignals () const
> +{
> + if (m_opaque_ptr)
> + {
> + int32_t num_signals = 0;
> + for (
> + int32_t signo = m_opaque_ptr->GetFirstSignalNumber();
> + signo != LLDB_INVALID_SIGNAL_NUMBER;
> + signo = m_opaque_ptr->GetNextSignalNumber(signo)
> + )
> + {
> + num_signals++;
> + }
> + return num_signals;
> + }
> + return LLDB_INVALID_SIGNAL_NUMBER;
> +}
> +
> +int32_t
> +SBUnixSignals::GetSignalAtIndex (int32_t index) const
> +{
> + if (m_opaque_ptr)
> + {
> + int32_t idx = 0;
> + for (
> + int32_t signo = m_opaque_ptr->GetFirstSignalNumber();
> + signo != LLDB_INVALID_SIGNAL_NUMBER;
> + signo = m_opaque_ptr->GetNextSignalNumber(signo)
> + )
> + {
> + if (index == idx) return signo;
> + idx++;
> + }
> + }
> + return LLDB_INVALID_SIGNAL_NUMBER;
> +}
> --
> 1.8.1.3
>
> <0001-Add-the-ability-to-control-the-signal-disposition-vi.patch>
More information about the lldb-dev
mailing list