segv-handler-gdb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +4 -0
- data/Gemfile +20 -0
- data/LICENSE.md +3 -0
- data/README.md +86 -0
- data/Rakefile +26 -0
- data/doc/text/lgpl-3.txt +165 -0
- data/ext/segv-handler-gdb/extconf.rb +18 -0
- data/ext/segv-handler-gdb/segv-handler-gdb.c +198 -0
- data/lib/segv-handler-gdb.rb +17 -0
- data/lib/segv-handler-gdb/version.rb +18 -0
- data/segv-handler-gdb.gemspec +51 -0
- metadata +92 -0
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
source "https://rubygems.org"
|
19
|
+
|
20
|
+
gemspec
|
data/LICENSE.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
segv-handler-gdb is a gem for debugging C extension that causes
|
4
|
+
SEGV. It dumps C level backtrace by GDB on SEGV. If your C extension
|
5
|
+
is built with `gcc -O0 -g3`, the backtrace includes useful information
|
6
|
+
for debug.
|
7
|
+
|
8
|
+
## Supported platform
|
9
|
+
|
10
|
+
segv-handler-gdb works on Linux. It may also work on other POSIX
|
11
|
+
systems such as FreeBSD and OS X but it is not tested yet.
|
12
|
+
|
13
|
+
Here is a list of supported platform:
|
14
|
+
|
15
|
+
* Debian GNU/Linux
|
16
|
+
* (If you confirm that segv-handler-gdb works on your platform,
|
17
|
+
please report it.)
|
18
|
+
|
19
|
+
## Requirments
|
20
|
+
|
21
|
+
Here is a list of required programs:
|
22
|
+
|
23
|
+
* gdb
|
24
|
+
|
25
|
+
## Install
|
26
|
+
|
27
|
+
% gem install segv-handler-gdb
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
You just require segv-handler-gdb library like the following:
|
32
|
+
|
33
|
+
require "segv-handler-gdb"
|
34
|
+
|
35
|
+
You can use segv-handler-gdb without changing your Ruby script:
|
36
|
+
|
37
|
+
% ruby -rsegv-handler-gdb YOUR-RUBY-SCRIPT.rb
|
38
|
+
|
39
|
+
If your Ruby script crashes, you find C level backtrace at
|
40
|
+
`/tmp/segv-handler-gdb.#{Process.pid}.log`.
|
41
|
+
|
42
|
+
## Customization
|
43
|
+
|
44
|
+
You can customize segv-handler-gdb behavior by some environment
|
45
|
+
variables.
|
46
|
+
|
47
|
+
### Backtrace dump path
|
48
|
+
|
49
|
+
Backtrace is dumped to `/tmp/segv-handler-gdb.#{Process.pid}.log` by
|
50
|
+
default. You can customize the path by `SEGV_HANDLER_GDB_PATH`
|
51
|
+
environment variable.
|
52
|
+
|
53
|
+
There are some special values for the environment variable:
|
54
|
+
|
55
|
+
* `-`: Backtrace is dumped to the standard output.
|
56
|
+
* `+`: Backtrace is dumped to the standard error output.
|
57
|
+
|
58
|
+
Here is a sample command line to dump backtrace to the standard
|
59
|
+
output:
|
60
|
+
|
61
|
+
% SEGV_HANDLER_GDB_PATH=- ruby -rsegv-handlder-gdb YOUR-RUBY-SCRIPT.rb
|
62
|
+
|
63
|
+
### Temporary directory path
|
64
|
+
|
65
|
+
segv-handler-gdb creates a temporary file to temporary
|
66
|
+
directory. `/tmp` directory is used as the temporary directory by
|
67
|
+
default. You can customize the temporary directory by the following
|
68
|
+
environment variables:
|
69
|
+
|
70
|
+
* `TMPDIR`
|
71
|
+
* `TMP`
|
72
|
+
* `TEMP`
|
73
|
+
|
74
|
+
The order of the above list shows priority. If `TMPDIR` is specified,
|
75
|
+
`TMP` is not used.
|
76
|
+
|
77
|
+
If all of these environment variables aren't specified, `/tmp` is used
|
78
|
+
as the temporary directory.
|
79
|
+
|
80
|
+
## Author
|
81
|
+
|
82
|
+
* Kouhei Sutou \<kou@clear-code.com\>
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
LGPLv3 or later. See doc/text/lgpl-3.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "bundler/gem_helper"
|
19
|
+
|
20
|
+
base_dir = File.dirname(__FILE__)
|
21
|
+
|
22
|
+
helper = Bundler::GemHelper.new(base_dir)
|
23
|
+
def helper.version_tag
|
24
|
+
version
|
25
|
+
end
|
26
|
+
helper.install
|
data/doc/text/lgpl-3.txt
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "mkmf"
|
17
|
+
|
18
|
+
create_makefile("segv_handler_gdb")
|
@@ -0,0 +1,198 @@
|
|
1
|
+
/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2
|
+
/*
|
3
|
+
Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <ruby.h>
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
#include <signal.h>
|
23
|
+
#include <sys/types.h>
|
24
|
+
#include <sys/wait.h>
|
25
|
+
#include <sys/stat.h>
|
26
|
+
#include <unistd.h>
|
27
|
+
#include <fcntl.h>
|
28
|
+
#include <errno.h>
|
29
|
+
|
30
|
+
#define MESSAGE_BUFFER_SIZE 4096
|
31
|
+
|
32
|
+
typedef int shg_bool;
|
33
|
+
|
34
|
+
#define SHG_TRUE (!SHG_FALSE)
|
35
|
+
#define SHG_FALSE (0)
|
36
|
+
|
37
|
+
static struct sigaction original_segv_action;
|
38
|
+
|
39
|
+
static const char *
|
40
|
+
temporary_diretory_path (void)
|
41
|
+
{
|
42
|
+
const char *path = NULL;
|
43
|
+
|
44
|
+
if (!path) {
|
45
|
+
path = getenv("TMPDIR");
|
46
|
+
}
|
47
|
+
if (!path) {
|
48
|
+
path = getenv("TMP");
|
49
|
+
}
|
50
|
+
if (!path) {
|
51
|
+
path = getenv("TEMP");
|
52
|
+
}
|
53
|
+
if (!path) {
|
54
|
+
path = "/tmp";
|
55
|
+
}
|
56
|
+
|
57
|
+
return path;
|
58
|
+
}
|
59
|
+
|
60
|
+
static void
|
61
|
+
print_system_error (int output_fd, const char *message)
|
62
|
+
{
|
63
|
+
FILE *output;
|
64
|
+
output = fdopen(dup(output_fd), "w");
|
65
|
+
fprintf(output, "%s: %s\n", message, strerror(errno));
|
66
|
+
fclose(output);
|
67
|
+
}
|
68
|
+
|
69
|
+
static shg_bool
|
70
|
+
create_gdb_command_file (char *gdb_command_path, int output_fd)
|
71
|
+
{
|
72
|
+
int gdb_command_fd;
|
73
|
+
const char *gdb_command =
|
74
|
+
"thread apply all backtrace full\n"
|
75
|
+
"quit\n";
|
76
|
+
ssize_t written;
|
77
|
+
|
78
|
+
gdb_command_fd = mkstemp(gdb_command_path);
|
79
|
+
if (gdb_command_fd == -1) {
|
80
|
+
print_system_error(output_fd,
|
81
|
+
"[segv-handler-gdb] failed to create temporary file");
|
82
|
+
return SHG_FALSE;
|
83
|
+
}
|
84
|
+
|
85
|
+
written = write(gdb_command_fd, gdb_command, strlen(gdb_command));
|
86
|
+
close(gdb_command_fd);
|
87
|
+
|
88
|
+
if (written == -1) {
|
89
|
+
print_system_error(output_fd,
|
90
|
+
"[segv-handler-gdb] failed to write GDB command");
|
91
|
+
unlink(gdb_command_path);
|
92
|
+
return SHG_FALSE;
|
93
|
+
}
|
94
|
+
|
95
|
+
return SHG_TRUE;
|
96
|
+
}
|
97
|
+
|
98
|
+
static void
|
99
|
+
run_gdb (const char *gdb_command_path, int output_fd)
|
100
|
+
{
|
101
|
+
pid_t gdb_pid;
|
102
|
+
|
103
|
+
gdb_pid = fork();
|
104
|
+
if (gdb_pid == 0) {
|
105
|
+
char target_pid[256];
|
106
|
+
sprintf(target_pid, "%u", getppid());
|
107
|
+
dup2(output_fd, STDOUT_FILENO);
|
108
|
+
dup2(output_fd, STDERR_FILENO);
|
109
|
+
execlp("gdb",
|
110
|
+
"gdb",
|
111
|
+
"--batch",
|
112
|
+
"--command", gdb_command_path,
|
113
|
+
"--pid", target_pid,
|
114
|
+
NULL);
|
115
|
+
_exit(EXIT_FAILURE);
|
116
|
+
} else if (gdb_pid == -1) {
|
117
|
+
print_system_error(output_fd,
|
118
|
+
"[segv-handler-gdb] failed to fork gdb");
|
119
|
+
} else {
|
120
|
+
int status;
|
121
|
+
int options = 0;
|
122
|
+
waitpid(gdb_pid, &status, options);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
static void
|
127
|
+
show_gdb_backtrace (void)
|
128
|
+
{
|
129
|
+
const char *segv_handler_gdb_path;
|
130
|
+
char segv_handler_gdb_path_default[PATH_MAX];
|
131
|
+
char gdb_command_path[PATH_MAX];
|
132
|
+
int output_fd;
|
133
|
+
shg_bool output_fd_need_close = SHG_FALSE;
|
134
|
+
|
135
|
+
sprintf(gdb_command_path,
|
136
|
+
"%s/segv-handler-gdb-XXXXXX",
|
137
|
+
temporary_diretory_path());
|
138
|
+
segv_handler_gdb_path = getenv("SEGV_HANDLER_GDB_PATH");
|
139
|
+
if (!segv_handler_gdb_path) {
|
140
|
+
sprintf(segv_handler_gdb_path_default,
|
141
|
+
"%s/segv-handler-gdb.%u.log",
|
142
|
+
temporary_diretory_path(),
|
143
|
+
getpid());
|
144
|
+
segv_handler_gdb_path = segv_handler_gdb_path_default;
|
145
|
+
}
|
146
|
+
if (strcmp(segv_handler_gdb_path, "-") == 0) {
|
147
|
+
output_fd = STDOUT_FILENO;
|
148
|
+
} else if (strcmp(segv_handler_gdb_path, "+") == 0) {
|
149
|
+
output_fd = STDERR_FILENO;
|
150
|
+
} else {
|
151
|
+
output_fd = open(segv_handler_gdb_path,
|
152
|
+
O_WRONLY | O_CREAT | O_APPEND,
|
153
|
+
S_IRUSR | S_IWUSR);
|
154
|
+
if (output_fd == -1) {
|
155
|
+
char message[MESSAGE_BUFFER_SIZE];
|
156
|
+
snprintf(message,
|
157
|
+
MESSAGE_BUFFER_SIZE,
|
158
|
+
"[segv-handler-gdb] failed to open output path. "
|
159
|
+
"stderr is used instead: <%s>",
|
160
|
+
segv_handler_gdb_path);
|
161
|
+
perror(message);
|
162
|
+
output_fd = STDERR_FILENO;
|
163
|
+
} else {
|
164
|
+
output_fd_need_close = SHG_TRUE;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
if (create_gdb_command_file(gdb_command_path, output_fd)) {
|
169
|
+
run_gdb(gdb_command_path, output_fd);
|
170
|
+
unlink(gdb_command_path);
|
171
|
+
}
|
172
|
+
|
173
|
+
if (output_fd_need_close) {
|
174
|
+
close(output_fd);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
static void
|
179
|
+
show_gdb_backtrace_handler (int signum)
|
180
|
+
{
|
181
|
+
show_gdb_backtrace();
|
182
|
+
if (sigaction(signum, &original_segv_action, NULL) == 0) {
|
183
|
+
kill(getpid(), signum);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
void
|
188
|
+
Init_segv_handler_gdb (void)
|
189
|
+
{
|
190
|
+
struct sigaction segv_action;
|
191
|
+
|
192
|
+
segv_action.sa_handler = show_gdb_backtrace_handler;
|
193
|
+
sigemptyset(&(segv_action.sa_mask));
|
194
|
+
segv_action.sa_flags = 0;
|
195
|
+
if (sigaction(SIGSEGV, &segv_action, &original_segv_action) == -1) {
|
196
|
+
rb_sys_fail("[segv-handler-gdb] failed to set SEGV handler");
|
197
|
+
}
|
198
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "segv_handler_gdb.so"
|
17
|
+
require "segv-handler-gdb/version"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module SEGVHandlerGDB
|
17
|
+
VERSION = "1.0.0"
|
18
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
base_dir = File.dirname(__FILE__)
|
19
|
+
|
20
|
+
$LOAD_PATH.unshift(File.join(base_dir, "lib"))
|
21
|
+
require "segv-handler-gdb/version"
|
22
|
+
|
23
|
+
Gem::Specification.new do |spec|
|
24
|
+
spec.name = "segv-handler-gdb"
|
25
|
+
spec.version = SEGVHandlerGDB::VERSION
|
26
|
+
|
27
|
+
spec.authors = ["Kouhei Sutou"]
|
28
|
+
spec.email = ["kou@clear-code.com"]
|
29
|
+
|
30
|
+
spec.summary = "Dump C level backtrace by GDB on SEGV"
|
31
|
+
spec.description = "It helps that you debug C extension that causes SEGV."
|
32
|
+
|
33
|
+
spec.files = ["README.md", "LICENSE.md", "Rakefile", "Gemfile", ".yardopts"]
|
34
|
+
spec.files += Dir.glob("doc/text/*.*")
|
35
|
+
spec.files += ["#{spec.name}.gemspec"]
|
36
|
+
Dir.chdir(base_dir) do
|
37
|
+
spec.files += Dir.glob("lib/**/*.rb")
|
38
|
+
spec.files += Dir.glob("ext/**/*.{c,rb}")
|
39
|
+
spec.extensions = ["ext/segv-handler-gdb/extconf.rb"]
|
40
|
+
end
|
41
|
+
|
42
|
+
spec.homepage = "https://github.com/kou/segv-handler-gdb"
|
43
|
+
spec.licenses = ["LGPLv3"]
|
44
|
+
spec.require_paths = ["lib", "ext/segv-handler-gdb"]
|
45
|
+
|
46
|
+
spec.required_ruby_version = ">= 1.9.3"
|
47
|
+
|
48
|
+
spec.add_development_dependency("rake")
|
49
|
+
spec.add_development_dependency("bundler")
|
50
|
+
end
|
51
|
+
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: segv-handler-gdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kouhei Sutou
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: It helps that you debug C extension that causes SEGV.
|
47
|
+
email:
|
48
|
+
- kou@clear-code.com
|
49
|
+
executables: []
|
50
|
+
extensions:
|
51
|
+
- ext/segv-handler-gdb/extconf.rb
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- README.md
|
55
|
+
- LICENSE.md
|
56
|
+
- Rakefile
|
57
|
+
- Gemfile
|
58
|
+
- .yardopts
|
59
|
+
- doc/text/lgpl-3.txt
|
60
|
+
- segv-handler-gdb.gemspec
|
61
|
+
- lib/segv-handler-gdb/version.rb
|
62
|
+
- lib/segv-handler-gdb.rb
|
63
|
+
- ext/segv-handler-gdb/segv-handler-gdb.c
|
64
|
+
- ext/segv-handler-gdb/extconf.rb
|
65
|
+
homepage: https://github.com/kou/segv-handler-gdb
|
66
|
+
licenses:
|
67
|
+
- LGPLv3
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
- ext/segv-handler-gdb
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.9.3
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.23
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Dump C level backtrace by GDB on SEGV
|
91
|
+
test_files: []
|
92
|
+
has_rdoc:
|