Improve as per bombela's suggestions, add test

This commit is contained in:
bastih 2013-05-26 16:31:58 +00:00
parent fea5667108
commit 5a638eafd8
3 changed files with 57 additions and 15 deletions

View File

@ -69,6 +69,7 @@ set(TESTS
invalidread
suicide
divbyzero
select_signals
)
foreach(test ${TESTS})

View File

@ -2007,8 +2007,11 @@ private:
#ifdef BACKWARD_SYSTEM_LINUX
std::vector<int> make_default_signals() {
const int signals[] = {
class SignalHandling {
public:
static std::vector<int> make_default_signals() {
const int signals[] = {
// default action: Core
SIGILL,
SIGABRT,
@ -2037,20 +2040,10 @@ std::vector<int> make_default_signals() {
SIGXCPU,
SIGXFSZ
};
std::vector<int> result;
for (const int* sig = signals;
sig != signals + sizeof signals / sizeof *signals; ++sig) {
result.push_back(*sig);
}
return result;
}
return std::vector<int>(signals, signals + sizeof signals);
}
const std::vector<int> default_signals = make_default_signals();
class SignalHandling {
public:
SignalHandling(const std::vector<int>& signals = default_signals): _loaded(false) {
SignalHandling(const std::vector<int>& signals = make_default_signals()) : _loaded(false) {
bool success = true;
const size_t stack_size = 1024 * 1024 * 8;

48
test/select_signals.cpp Normal file
View File

@ -0,0 +1,48 @@
/*
* test/segfault.cpp
* Copyright 2013 Google Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
//#define BACKWARD_SYSTEN_UNKNOWN
//#define BACKWARD_HAS_UNWIND 0
//#define BACKWARD_CXX98
#include "backward.hpp"
#include <stdio.h>
#include "test/test.hpp"
using namespace backward;
void badass_function()
{
char* ptr = (char*)42;
*ptr = 42;
}
TEST (select_signals)
{
std::vector<int> signals;
signals.push_back(SIGSEGV);
SignalHandling sh(signals);
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
badass_function();
}