summaryrefslogtreecommitdiff
path: root/doc/source
diff options
context:
space:
mode:
authorjvoisin2018-01-03 11:53:01 +0100
committerjvoisin2018-01-03 11:53:01 +0100
commitd55aa5bdf8ef5cdeab23e42678d6a7fdc537417c (patch)
tree4344c22ef2b47837356350bdc0a2c4a17225f614 /doc/source
parentbd31eb5fbfbe6c447ebe529232a71f4b2deed9e4 (diff)
Document how to debug Snuffleupagus
Diffstat (limited to 'doc/source')
-rw-r--r--doc/source/debug.rst120
-rw-r--r--doc/source/faq.rst2
2 files changed, 121 insertions, 1 deletions
diff --git a/doc/source/debug.rst b/doc/source/debug.rst
new file mode 100644
index 0000000..647c7e5
--- /dev/null
+++ b/doc/source/debug.rst
@@ -0,0 +1,120 @@
1:orphan:
2
3.. This page is included in the FAQ, but is not present in any ToC,
4 because its content is pretty technical, and "normal users" shouldn't
5 need to read it.
6
7Debugging crashes
8=================
9
10.. _testsuite_fail:
11
12The testsuite is failling
13-------------------------
14
15We're using `php qa <https://qa.php.net/>`__ tests format for our testsuite,
16it is automatically run when you're building snuffleupagus.
17
18If it happens to have unexpected failures (Since we're using `TDD <https://en.wikipedia.org/wiki/Test-driven_development>`__ as much
19as we can, we do have some expected failures), please do `open an issue <https://github.com/nbs-system/snuffleupagus/issues/new>`__
20on our bugtracker, and attach the generated ``.diff`` and ``.out`` files to it,
21so we can see what's happening.
22
23Snuffleupagus is crashing
24-------------------------
25
26While do do our very best to make snuffleupagus solid as possible, we're humans,
27and computers are hard, so crashes can happen. If you're encountering one in production,
28please try to launch the `testsuite <https://github.com/nbs-system/snuffleupagus/blob/master/CONTRIBUTING.md#3-get-the-test-suite-running>`__
29to see if it's failing. If it does, please :ref:`tell us <testsuite_fail>`.
30
31If the testsuite is passing, odds are that you're encountering an issue tied to your php code,
32so unless you're able to provide it to us, or are willing to give us a shell on your infrastructure,
33you'll have to gather information on your own. Don't be afraid, it's not that hard.
34
35The first step is to build snuffleupagus with debug symbols, with ``make debug``.
36
37Snuffleupagus is crashing at startup
38^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39
40If you can can reproduce the crash with ``php -d "sp.configuration_file=/path/to/your/config/config.rules" -d "extension=/complete/path/to/debug/snuffleupagus.so"``,
41please run it in ``gdb``, with ``gdb --args /usr/bin/php -d "sp.configuration_file=/path/to/your/config/config.rules" -d "extension=/complete/path/to/debug/snuffleupagus.so"``.
42
43In ``gdb``, type ``run`` to *run*, the crash should now appear. Type ``bt`` to get a complete backtrace,
44and ``info registers`` to get the content of the registers. Please provide
45us the complete output of gdb in the issue. It should look like this:
46
47::
48
49 $ gdb --args /usr/bin/php7.0 -d "sp.configuration_file=/config_disabled_functions_param_alias.ini" -d "extension=/home/jvoisin/snuffleupagus/src/modules/snuffleupagus.so"
50 (gdb) r
51 Starting program: /usr/bin/php7.0 -d sp.configuration_file=/config_disabled_functions_param_alias.ini -d extension=/home/jvoisin/snuffleupagus/src/modules/snuffleupagus.so
52
53 Program received signal SIGSEGV, Segmentation fault.
54 0x00007fffe25558f5 in parse_str (line=0x7fffddd3602d "\"system\").alias(\"1\").drop();", keyword=0x7fffe25673ec ".function(", retval=0x7fffddd33028) at /home/jvoisin/snuffleupagus/src/sp_config.c:107
55 107 char a = *x;
56 (gdb) bt
57 #0 0x00007fffe25558f5 in parse_str (line=0x7fffddd3602d "\"system\").alias(\"1\").drop();", keyword=0x7fffe25673ec ".function(", retval=0x7fffddd33028) at /home/jvoisin/snuffleupagus/src/sp_config.c:107
58 #1 0x00007fffe2555e2c in parse_keywords (funcs=0x7fffffffc700, line=0x7fffddd3602d "\"system\").alias(\"1\").drop();") at /home/jvoisin/snuffleupagus/src/sp_config_utils.c:11
59 #2 0x00007fffe2562ff6 in parse_disabled_functions (line=0x7fffddd36023 ".function(\"system\").alias(\"1\").drop();") at /home/jvoisin/snuffleupagus/src/sp_config_keywords.c:219
60 #3 0x00007fffe2555609 in parse_line (line=0x7fffddd36010 "sp.disable_function.function(\"system\").alias(\"1\").drop();") at /home/jvoisin/snuffleupagus/src/sp_config.c:46
61 #4 0x00007fffe2555bf5 in sp_parse_config (conf_file=0x7ffff7e14028 "/config_disabled_functions_param_alias.ini") at /home/jvoisin/snuffleupagus/src/sp_config.c:182
62 #5 0x00007fffe2555331 in OnUpdateConfiguration (entry=0x7fffddd39010, new_value=0x7ffff7e14010, mh_arg1=0x0, mh_arg2=0x0, mh_arg3=0x0, stage=1) at /home/jvoisin/snuffleupagus/src/snuffleupagus.c:176
63 #6 0x00005555557d2861 in zend_register_ini_entries ()
64 #7 0x00007fffe2554fc9 in zm_startup_snuffleupagus (type=1, module_number=53) at /home/jvoisin/snuffleupagus/src/snuffleupagus.c:92
65 #8 0x00005555557bb9ae in zend_startup_module_ex ()
66 #9 0x00005555557bba5c in ?? ()
67 #10 0x00005555557c902a in zend_hash_apply ()
68 #11 0x00005555557bbd1a in zend_startup_modules ()
69 #12 0x00005555557555db in php_module_startup ()
70 #13 0x000055555584d02d in ?? ()
71 #14 0x0000555555638581 in main ()
72 (gdb) info registers
73 rax 0x0 0
74 rbx 0x7fffe2562acc 140736990685900
75 rcx 0x7fffe25558cd 140736990632141
76 rdx 0x7fffddd33028 140736914993192
77 rsi 0x7fffe25673ec 140736990704620
78 rdi 0x7fffddd3602d 140736915005485
79 rbp 0x7fffffffc660 0x7fffffffc660
80 rsp 0x7fffffffc620 0x7fffffffc620
81 r8 0xffff 65535
82 r9 0x1 1
83 r10 0x7ffff653b2a0 140737326068384
84 r11 0x0 0
85 r12 0x7ffff3b7cff0 140737282297840
86 r13 0x35 53
87 r14 0x15 21
88 r15 0x7fffe2565525 140736990696741
89 rip 0x7fffe25558f5 0x7fffe25558f5 <parse_str+40>
90 eflags 0x10202 [ IF RF ]
91 cs 0x33 51
92 ss 0x2b 43
93 ds 0x0 0
94 es 0x0 0
95 fs 0x0 0
96 gs 0x0 0
97 (gdb)
98
99
100
101Snuffleupagus is crashing at runtime
102^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103
104If snuffleupagus is crashing at runtime, odds are that it's triggered by a request,
105and that this behaviour is tied to your php code. The simplest way to gather information
106about what's going on is to generate a `core dump <https://en.wikipedia.org/wiki/Core_dump>`__,
107as written in the `php documentation <https://bugs.php.net/bugs-generating-backtrace.php>`__:
108
109You need to:
110
1111. Enable them with ``echo 0 > /proc/sys/kernel/core_uses_pid``
1122. Set a pattern for them with ``echo '/tmp/core-%e.%p' > /proc/sys/kernel/core_pattern``,
1133. Remove the maximum size of a dump ``ulimit -c unlimited``
114
115You're now ready to restart your PHP stack, using the *debug* version of Snuffleupagus,
116and right after the crash, you should get a (big) file in your ``/tmp``, starting with ``core``:
117It's a complete memory snapshot of the state of the process during the crash.
118You can either send it to us (along with your ``snufflepagus.so`` binary),
119or if you're not comfortable with giving us a complete dump of your php memory,
120run ``gdb /usr/bin/php /tmp/core-php-fpm-1337``, then ``bt`` to get a backtrace, and ``info registers`` to get the registers.
diff --git a/doc/source/faq.rst b/doc/source/faq.rst
index d76a045..6a60d2f 100644
--- a/doc/source/faq.rst
+++ b/doc/source/faq.rst
@@ -110,7 +110,7 @@ issues, as stated in their `documentation <https://wiki.php.net/security#not_a_s
110We do think that a security issue that "requires the use of code or settings known to be insecure" 110We do think that a security issue that "requires the use of code or settings known to be insecure"
111is still a security issue, and should be treated as such. 111is still a security issue, and should be treated as such.
112 112
113We don't have the pretention to state that Snuffleupagus will magically solve 113We don't have the pretension to state that Snuffleupagus will magically solve
114all your security issues, but we believe that it might definitely help. 114all your security issues, but we believe that it might definitely help.
115 115
116Why should I send you bugs, security issues and patches? 116Why should I send you bugs, security issues and patches?