Changes between Version 10 and Version 11 of TracTroubleshooting
- Timestamp:
- Feb 8, 2015, 3:47:47 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracTroubleshooting
v10 v11 1 1 [[PageOutline(2-5)]] 2 = Trac Troubleshooting or ''"When Things Go Wrong"'' = 2 3 = Trac Troubleshooting 3 4 4 5 This is a collection of recipes you can use to troubleshoot Trac and help us to fix bugs. 5 6 6 == RTFW (''Read the Fine Wiki'') ==7 == RTFW (''Read the Fine Wiki'') 7 8 8 Trac comes with extensive documentation in form of a collection of Wiki pages. 9 Some are present in each Trac installation (those that are part of the TracGuide), while most are only found on this site. 10 Among the latter is the TracFaq (frequently asked questions). 9 Trac comes with extensive documentation in form of [http://trac.edgewall.org/wiki Wiki pages]. 10 Some are present in each Trac installation, for example those that are part of the TracGuide, while most are only found on this site, for example the TracFaq (frequently asked questions). 11 11 12 A fewsubsystems have their dedicated page with a troubleshooting section:12 Some subsystems have their dedicated page with a troubleshooting section: 13 13 - PySqlite#Troubleshooting 14 - MySqlDb#Troubleshooting 14 15 - TracSubversion#Troubleshooting 15 16 - TracModPython#Troubleshooting … … 17 18 - TracNotification#Troubleshooting 18 19 19 Then, use the TracSearch to dig through existing tickets , looking for past issues similar to yours thanks to carefully selected keywords. The Trac ["MailingList"]s are also usually of some help.20 Then, use the TracSearch to dig through existing tickets describing issues similar to yours. The Trac ["MailingList"]s are also usually of some help. 20 21 21 22 And don't forget it's a Wiki, so feel free to enhance its content while you're at it. 22 23 23 Now, assuming you're facing a new problem, the next step is to try to find out what's really wrong.24 If you're facing a new problem, the next step is to try to find out the root cause. 24 25 25 == Debugging Trac ==26 == Debugging Trac 26 27 27 === Python errors ===28 === Python errors 28 29 29 First, it should be noted that debugging Python errors in Trac is much more convenient since [milestone:0.11]: 30 when you get an internal error and provided you have the TRAC_ADMIN privilege, the error page will show you an interactive stack trace, which enables you to see the faulty line of code in its context and to view the values of the local variables. 30 Debugging Python errors in Trac is much more convenient since [milestone:0.11]: when you get an internal error and provided you have the TRAC_ADMIN privilege, the error page will show you an interactive stack trace, which enables you to see the faulty line of code in its context and to view the values of the local variables. 31 31 32 32 Now, before describing the specific debugging techniques you can use, some basic understanding of the way Trac is working is needed. 33 33 34 Trac uses a model-view-controller approach. The ''controller'' is a Python class called a "module" which inherits from the Component class implementing the `IRequestHandler` interface (a ''Component'' is the basic building block in the TracDev/ComponentArchitecture, it ''implements'' some ''Interface''s). The controller reacts on user requests and prepares the data that will be used by a template engine to fill the adequate template, in order to render the ''view'' which will be sent back to the user.34 Trac uses a [http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller model-view-controller approach]. The ''controller'' is a Python class called a "module" which inherits from the Component class implementing the `IRequestHandler` interface. A ''Component'' is the basic building block in the TracDev/ComponentArchitecture, it ''implements'' some ''Interface''s. The controller reacts on user requests and prepares the data that will be used by a template engine to fill the adequate template, in order to render the ''view'' which will be sent back to the user. 35 35 36 Other resources from TracDev can be useful reading here, in particular TracDev/HowTracWorks.36 The TracDev collection of development guides can be useful here. 37 37 38 ==== Inspecting the Template data ====39 ===== Clearsilver's HDF =====38 ==== Inspecting the Template data 39 ===== Clearsilver's HDF 40 40 41 41 Before [milestone:0.11], Trac was using ClearSilver as its template engine. 42 42 Clearsilver uses a so-called ''Hierarchical Data Format'' which is prepared by the controller. 43 In order to inspect this ''HDF'', a simple trick is to append to the URL the `?hdfdump=1` string (or `&hdfdump=1`, in case other parameters are already present in the URL).43 In order to inspect this ''HDF'', a simple trick is to append to the URL the `?hdfdump=1` string or `&hdfdump=1`, in case other parameters are already present in the URL. 44 44 45 ===== Genshi data dictionary ===== 45 ===== Genshi data dictionary 46 46 47 Starting with [milestone:0.11], Trac uses the [http://genshi.edgewall.org Genshi] template engine. 47 48 As this template engine is also written in Python, no specific data format is needed and a simple Python dictionary is used to feed the engine. It's very easy to inspect any part of this data by modifying the template and inserting `${pprint(...)}` statements, possibly in between `<pre>...</pre>` tags. … … 52 53 }}} 53 54 54 ==== Modifying the Code ====55 ==== Modifying the Code 55 56 56 TracStandalone is the indispensable companion whether you intend to develop or debug Trac. In particular, check out the `-r` (auto-reload) feature, which will make Trac notice any change to one of its source file and restart automatically. You can therefore see Trac react immediately to your code changes (provided you don't have syntax errors outside of a method...).57 TracStandalone is the indispensable companion whether you intend to develop or debug Trac. In particular, check out the `-r` (auto-reload) feature, which will make Trac notice any change to one of its source file and restart automatically. You can therefore see Trac react immediately to your code changes, provided you don't have syntax errors outside of a method. 57 58 58 In this setup, you're free to try out modification, dump additional information to the log or insert direct `print` statements ... (ugly but effective way of debugging).59 In this setup, you're free to try out modification, dump additional information to the log or insert direct `print` statements; an ugly but effective way of debugging. 59 60 60 It 's probably possible to run `tracd` with a debugger, but I'll skip that paragraph for now ;)61 It may even be possible to run `tracd` with a debugger, but not explored here. 61 62 62 Best is to start from a [TracSubversion checkout] of the pristine source code you're interested to debug (or develop for).63 Best is to start from a [TracSubversion checkout] of the pristine source code you're interested to debug or develop for. 63 64 Then, you can run the standalone server by doing: 64 65 {{{ … … 70 71 $ python trac/web/standalone.py <options> 71 72 }}} 72 Note that the very first time (in a fresh working copy), you'll have to at least initialize the ''Trac.egg-info'' folder, by doing:73 Note that the very first time in a fresh working copy, you'll have to at least initialize the ''Trac.egg-info'' folder, by doing: 73 74 {{{ 74 75 $ python setup.py egg_info 75 76 }}} 76 77 78 === System Errors 77 79 80 By system errors, we mean serious issues like segmentation faults or process hangs. This usually involves some C extensions used by Trac, either due to a bug or a misconfiguration in those libraries, or to an incorrect usage within Trac. 78 81 79 === System Errors === 82 In this case, the first thing to do is to identify the subsystem involved, by getting the ''stack trace'' of the process. This can be done using `gdb` on Unix or [http://www.microsoft.com/whdc/devtools/debugging/default.mspx WinDbg] on Windows or MS Developer Studio. 80 83 81 By system errors, we mean serious issues like segmentation faults or process hangs. 82 This usually involves some C extensions used by Trac, either due to a bug or a misconfiguration in those libraries, or to an incorrect usage within Trac. 83 84 In this case, the first thing to do is to identify the subsystem involved, by getting the ''stack trace'' of the process. This can be done using `gdb` on Unix or [http://www.microsoft.com/whdc/devtools/debugging/default.mspx WinDbg] on Windows (or MS Developer Studio). 85 86 With GDB, you can also make the link between the C stack trace and the Python backtrace. For this, you need to teach `gdb` a few additional commands: Get the following [http://hg.python.org/cpython/file/2.7/Misc/gdbinit gdbinit] script, and "source" it. 84 With [https://www.gnu.org/software/gdb/ GDB] you can also make the link between the C stack trace and the Python backtrace. For this, you need to teach `gdb` a few additional commands: Get the following [http://hg.python.org/cpython/file/2.7/Misc/gdbinit gdbinit] script, and "source" it. 87 85 You should be able to issue interesting commands like `pystack`, `pyframe`, `pylocals`, etc. 88 86 89 87 If you're using a gdb 7.x version built "`--with-python`", you can instead "`source`" [http://hg.python.org/cpython/file/2.7/Tools/gdb/libpython.py libpython.py] and use `py-bt` (see also [http://sourceware.org/gdb/current/onlinedocs/gdb/Python.html Scripting gdb using Python]). 90 88 91 ==== Debugging Segmentation Faults ====89 ==== Debugging Segmentation Faults 92 90 93 Getting a backtrace for `tracd` 91 Getting a backtrace for `tracd`: 94 92 {{{ 95 93 $ gdb $(which python) 96 94 (gdb) run /opt/trac-0.10/scripts/tracd -p 8080 /srv/trac/yourproject 97 95 }}} 98 (of course, adapt the paths and the options to match what's relevant for you) 96 Of course, adapt the paths and the options to match what's relevant for you. 99 97 100 98 Getting a backtrace for Apache's `httpd` can be done in a similar way: … … 108 106 Another very useful command is "`info shared`", which gives you a list of the shared libraries actually used. 109 107 110 ==== Debugging a Hanging Process ====108 ==== Debugging a Hanging Process 111 109 112 110 Here it might be interesting to just "attach" to an already running process: … … 143 141 }}} 144 142 145 In the above, the `Loaded symbols ... ` part usually already interesting.146 You may find out that the libraries actually used are not the one that you expected, or you might notice interesting things, like the presence of mod_php triggering the load of an alternate sqlite library, etc.143 The `Loaded symbols ... ` part usually provides interesting information. 144 You may find out that the libraries actually used are not the one that you expected, or you might notice the presence of mod_php triggering the load of an alternate sqlite library. 147 145 That kind of information is also available without `gdb` by looking in the `/proc/28221/maps` file (to reuse the same pid from the above example). 148 146