[lldb-dev] Ignoring Signals via the API
Greg Clayton
gclayton at apple.com
Wed Jun 26 13:33:45 PDT 2013
On Jun 26, 2013, at 2:50 AM, Russell Harmon <russ at eatnumber1.com> wrote:
> Ok, I've attached a patch and inlined it below. Is git diff format ok?
Yep.
>
> I'll probably need to do some more work on it as I need to be able to set the disposition before I even attach to a process. Any thoughts on how that can be accomplished?
One way that would be handy would be to add new API to the SBLaunchInfo / SBAttachInfo.
class SBLaunchInfo {
....
SBUnixSignals
GetUnixSignals();
void
SetUnixSignals (SBUnixSignals unix_signals);
}
Repeat for SBAttachInfo. Then you could modify your signals to your liking and then launch or attach with the launch/attach info and it will do the right thing.
Greg
> --
> Russell Harmon
>
> From 704f23ec6d1aedfd66b6cf066215c4b95321a7fe 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 | 81 +++++++++++++++++++
> 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 | 73 +++++++++++++++++
> scripts/lldb.swig | 5 ++
> source/API/CMakeLists.txt | 1 +
> source/API/SBProcess.cpp | 14 ++++
> source/API/SBUnixSignals.cpp | 130 +++++++++++++++++++++++++++++++
> 13 files changed, 321 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..e738bb8
> --- /dev/null
> +++ b/include/lldb/API/SBUnixSignals.h
> @@ -0,0 +1,81 @@
> +//===-- 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;
> +
> + 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
> + GetFirstSignalNumber () const;
> +
> + int32_t
> + GetNextSignalNumber (int32_t current_signal) 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..9972d1d
> --- /dev/null
> +++ b/scripts/Python/interface/SBUnixSignals.i
> @@ -0,0 +1,73 @@
> +//===-- 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;
> +
> + 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
> + GetFirstSignalNumber () const;
> +
> + int32_t
> + GetNextSignalNumber (int32_t current_signal) const;
> +
> + %pythoncode %{
> + def get_unix_signals_list(self):
> + signals = []
> + sig = self.GetFirstSignalNumber()
> + while sig != LLDB_INVALID_SIGNAL_NUMBER:
> + signals.append(sig)
> + sig = self.GetNextSignalNumber(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..309a2fb
> --- /dev/null
> +++ b/source/API/SBUnixSignals.cpp
> @@ -0,0 +1,130 @@
> +//===-- 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;
> +}
> +
> +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::GetFirstSignalNumber () const
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->GetFirstSignalNumber();
> + return LLDB_INVALID_SIGNAL_NUMBER;
> +}
> +
> +int32_t
> +SBUnixSignals::GetNextSignalNumber (int32_t current_signal) const
> +{
> + if (m_opaque_ptr) return m_opaque_ptr->GetNextSignalNumber(current_signal);
> + return LLDB_INVALID_SIGNAL_NUMBER;
> +}
> --
> 1.8.1.3
>
> <0001-Add-the-ability-to-control-the-signal-disposition-vi.patch>_______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
More information about the lldb-dev
mailing list