Signal Handling with more normal Swift conventions

Overview

SignalHandler

Adds support for signal handlers in a fully swifty way.

Why this over raw signal handling or other packages.

Signal handler functions are part of the C language standard. This means that all of them that take a function pointer are @convention(c) so you cannot use typical swift closure syntax as you would normally expect. They instead become limited to only accessing global scope. This library takes that limitation away and lets you fully use swift closures and capture variables.

This library also takes inspiration from SwiftSystem and does its best to move away from the C names as much as possible to follow swift naming guidelines. For convenience the C names have been implimneted with unavailable annotations that direct you to the new more descriptive names.

Configuring Signals

The C language standard only defines 6 signals. Most other common ones are part of the UNIX. So this library has been configured in such a way that you can build it with or without the common UNIX signals by building with different environment variables.

If you set the NO_UNIX_SIGNALS environment variable then all non C signals will be disabled. To turn off one signal define NO_ and it will be disabled. You can specify any number of signals to turn off in this manner.

Debugging Signal Handlers with LLDB

When a process receives a signal as lldb is running it then by default captures the signal. To change this behavior you need to run the following command when you begin execution of your app.

process handle <SIGNAL_C_NAME> --pass true --stop false

This will then cause the signal to be passed on to the process you are debugging. If you are potentially debugging multiple signals then you should run this command for each of them. Because this can be tedious and obnoxious to run at the start of each run of your app, in Xcode you can do the following to help simplify the process.

  1. Create a breakpoint at the start of your app's execution. This should be a line that does work not just a declaration otherwise it will typically not run.
  2. Right click on the breakpoint.
  3. Select 'Edit Breakpoint...'.
  4. Click 'Add Action'.
  5. Ensure it is set to 'Debugger Command'.
  6. Put the lldb command from above into the text box.
  7. If you have other signals to catch hit the + and repeat steps 5-7 until you have set up all signals you care about.
  8. Check the Option box 'Automatically continue after evaluating actions'.

Now as you launch the app in the debugger it will automatically set the signals up for delivery each time as long as the breakpoint is active.

You might also like...
OpenAPI/Swagger 3.0 Parser and Swift code generator

SwagGen SwagGen is a library and command line tool for parsing and generating code for OpenAPI/Swagger 3.0 specs, completely written in Swift. Swagger

Homebrew for Swift packages

Swiftbrew A package manager that installs prebuilt Swift command line tool packages, or Homebrew for Swift packages. Installation Homebrew brew instal

The Swift code generator for your assets, storyboards, Localizable.strings, … β€” Get rid of all String-based APIs!
The Swift code generator for your assets, storyboards, Localizable.strings, … β€” Get rid of all String-based APIs!

SwiftGen SwiftGen is a tool to automatically generate Swift code for resources of your projects (like images, localised strings, etc), to make them ty

Start your next Open-Source Swift Framework πŸ“¦
Start your next Open-Source Swift Framework πŸ“¦

SwiftKit enables you to easily generate a cross platform Swift Framework from your command line. It is the best way to start your next Open-Source Swi

Easily generate cross platform Swift framework projects from the command line
Easily generate cross platform Swift framework projects from the command line

SwiftPlate Easily generate cross platform Swift framework projects from the command line. SwiftPlate will generate Xcode projects for you in seconds,

A Swift command line tool for generating your Xcode project
A Swift command line tool for generating your Xcode project

XcodeGen XcodeGen is a command line tool written in Swift that generates your Xcode project using your folder structure and a project spec. The projec

A Swift playground that comes pre-loaded with Plot, that can be used to explore the new component API.

PlotPlayground A Swift playground that comes pre-loaded with Plot, so that you can quickly try out the library and its new, SwiftUI-like API for build

[Accepted] WWDC21 Swift Student Challenge Submission

Hear See Tell us about the features and technologies you used in your Swift playground. Swift Playground Author Template: providing the general struct

🌳 Environment – a nicer, type-safe way of working with environment variables in Swift.

🌳 Environment Welcome to Environment – a nicer, type-safe way of working with environment variables in Swift. Usage Access Environment Variables The

Releases(v0.1.0)
  • v0.1.0(Dec 20, 2021)

    All of the most important parts of signal handling are in place and should work correctly but it needs some testing so this will let me/others start consuming it.

    Source code(tar.gz)
    Source code(zip)
Owner
Braden Scothern
Braden Scothern
WebDomHandling - A Swift Package for handling JavaScript code between WebKit and Swift implemented by WebKit

WebDomHandling A Swift Package for handling JavaScript code between WebKit and S

null 0 Jan 23, 2022
Ulangi is a language flashcards app with spaced repetition system and more.

Ulangi Open-source language learning tools Introduction Ulangi makes it easy for you to manage and create flash cards to learn languages. It comes wit

Ulangi 384 Jan 3, 2023
A Swift package for encoding and decoding Swift Symbol Graph files.

SymbolKit The specification and reference model for the Symbol Graph File Format. A Symbol Graph models a module, also known in various programming la

Apple 141 Dec 9, 2022
Delightful code generation for OpenAPI specs for Swift written in Swift

Create API Delightful code generation for OpenAPI specs for Swift written in Swi

Alexander Grebenyuk 286 Dec 23, 2022
A very simplistic state machine system for Swift while mainly used with Raylib on Swift

A very simplistic state machine system for Swift while mainly used with Raylib on Swift

Conifer Coniferoslav 2 Dec 12, 2022
A Swift SPM framework for running and managing Lua code from Swift

LuaKit A Swift Package for running and managing Lua code from Swift. Documentation For documentation, add this package as Swift Package Dependency, an

GGorAA 5 Nov 24, 2022
This is a Swift Package bundling different Train APIs into one simple Swift interface.

This is a Swift Package bundling different Train APIs into one simple Swift interface.

ICE Buddy 8 Jul 5, 2022
Beak 🐦 Peck into your Swift files from the command line

Beak ?? Peck into your Swift files from the command line Beak can take a standard Swift file and then list and run any public global functions in it v

Yonas Kolb 566 Dec 6, 2022
A Collection of PropertyWrappers to make custom Serialization of Swift Codable Types easy

CodableWrappers Simplified Serialization with Property Wrappers Move your Codable and (En/De)coder customization to annotations! struct YourType: Coda

null 393 Jan 5, 2023
Turn your Swift data model into a working CRUD app.

Model2App is a simple library that lets you quickly generate a CRUD iOS app based on just a data model defined in Swift. (CRUD - Create Read Update De

Q Mobile 132 Dec 22, 2022