What is GDB?
<div class="text"> Redis debugging guideRedis is developed with a great stress on stability: we do our best with every release to make sure you'll experience a very stable product and no crashes. However even with our best efforts it is impossible to avoid all the critical bugs with 100% of success. When Redis crashes it produces a detailed report of what happened,however sometimes looking at the crash report is not enough,nor it is possible for the Redis core team to reproduce the issue independently: in this scenario we need help from the user that is able to reproduce the issue. This little guide shows how to use GDB to provide all the informations the Redis developers will need to track the bug more easily. What is GDB?GDB is the Gnu Debugger: a program that is able to inspect the internal state of another program. Usually tracking and fixing a bug is an exercise in gathering more informations about the state of the program at the moment the bug happens,so GDB is an extremely useful tool. GDB can be used in two ways:
From the point of view of investigating Redis bugs we need to use both this GDB modes: the user able to reproduce the bug attaches GDB to his running Redis instance,and when the crash happens,he creates the This way the developer can perform all the inspections in his computer without the help of the user,and the user is free to restart Redis in the production environment. Compiling Redis without optimizationsBy default Redis is compiled with the It is better to attach GDB to Redis compiled without optimizations using the It is great if you make sure to recompile Redis with You should not be concerned with the loss of performances compiling Redis without optimizations,it is very unlikely that this will cause problems in your environment since it is usually just a matter of a small percentage because Redis is not very CPU-bound (it does a lot of I/O to serve queries). Attaching GDB to a running processIf you have an already running Redis server,you can attach GDB to it,so that if Redis will crash it will be possible to both inspect the internals and generate a After you attach GDB to the Redis process it will continue running as usually without any loss of performance,so this is not a dangerous procedure. In order to attach GDB the first thing you need is the process ID of the running Redis instance (the pid of the process). You can easily obtain it using
In the above example the process ID is 58414.
GDB will start and will attach to the running server printing something like the following:
After the crashRedis has a command to simulate a segmentation fault (in other words a bad crash) using the
As you can see GDB detected that Redis crashed,and was able to show me even the file name and line number causing the crash. This is already much better than the Redis crash report back trace (containing just function names and binary offsets). Obtaining the stack traceThe first thing to do is to obtain a full stack trace with GDB. This is as simple as using the bt command: (that is a short for backtrace):
This shows the backtrace,but we also want to dump the processor registers using the info registers command:
Please make sure to include both this outputs in your bug report. Obtaining the core fileThe next step is to generate the core dump,that is the image of the memory of the running Redis process. This is performed using the
Now you have the core dump to send to the Redis developer,but it is important to understand that this happens to contain all the data that was inside the Redis instance at the time of the crash: Redis developers will make sure to don't share the content with any other,and will delete the file as soon as it is no longer used for debugging purposes,but you are warned that sending the core file you are sending your data. If there are sensible stuff in the data set we suggest sending the dump directly to Salvatore Sanfilippo (that is the guy writing this doc) at the email address antirez at gmail dot com. What to send to developersFinally you can send everything to the Redis core team:
Thank youYour help is extremely important! Many issues can only be tracked this way,thanks! It is also possible that helping Redis debugging you'll be among the winners of the next . (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |