Changes

Jump to: navigation, search

Debugging Gramps

414 bytes added, 13:38, 23 June 2022
Hard crash
{{man note|This dcument is targeted at developers who are using a development environment with Gramps.|See the [https://www.gramps-project.org/wiki/index.php/Portal:Developers developers portal] about setting up a [https://www.gramps-project.org/wiki/index.php/Getting_started_with_Gramps_development Gramps development environment.]}}{{man tip|Note|When Please note when doing thisdebugging, please note |that the this document mentions <code>src/gramps.py </code> and <code>Gramps.py</code>. Since you never have both in a single Gramps setup, please use <code>src/gramps.py </code> when running Gramps 3.xand earlier, and <code>Gramps.py </code> for 4.xand newer.}}
An overview on how to debug Gramps.
When a hard crash occurs, you typically have no idea where the crash occurs. It is important to know the line where the crash occurs. So if you are able to reproduce the crash, restart Gramps with the command:
python -m trace -t src/grampsGramps.py
This will usually generate vast terminal output and slow the system down for that, so redirecting output to a file is usually good:
python -m trace -t src/grampsGramps.py >/tmp/trace.out
Then check the file "<code>/tmp/trace.out</code>" and save if needed, or redirect to somewhere else in the earlier step.
== Add debug statements ==
Gramps is run with the optimize flag.
python -O grampsGramps.py
This gives you the option of adding debug statements. You can use the __debug__ variable or the assert statement for this. This allows us to add code to Gramps that will be printed out when Gramps runs without the optimize flag:
python grampsGramps.py
More info: [http://docs.python.org/reference/simple_stmts.html#the-assert-statement]
Start Gramps with the --debug flag:
python grampsGramps.py --debug="name_of_the_logger"
This is useful when working in different parts, adding info output, and selecting on the command line with --debug the logger you want to see output with.
Add at the top of the file you want to use profiling:
from Utils gramps.gen.utils.debug import profile
Then, suppose you want to profile a save function on one of the editors. The save is called due to a connect done in the method _connect_signals. So, change the connect to save to a new method testsave you make:
See also [[GEPS_016:_Enhancing_Gramps_Processing_Speed]] for a sample of Profile Analysis.
 
And some [https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Profiling_Code Tips].
== Use the winpdb python debugger ==
{{man note|Note|There are some issues with the winpdb debugger. For a workaround see bug ticket: {{bug|2564}} }}
[httphttps://winpdbpypi.org/project/winpdb-reborn/ Winpdb] (Ubuntu: sudo apt-get install winpdb) is a graphical interface for the python debugger.
Start it with:
winpdb src/grampsGramps.py
[[Image:Winpdb.png|thumb|right|400px|Winpdb with Gramps loaded]]
LC_ALL=C G_DEBUG=fatal-warnings python -m trace -t Gramps.py
Different values possible: [https://developer.gnome.org/glib/2.3460/glib-running.html]
=== Learn More ===
To learn more about debugging python and C debugging with gdb, see [https://web.archive.org/web/20180806035308/http://grapsus.net:80/blog/post/Low-level-Python-debugging-with-GDB] and [httphttps://www.sourceware.org/gdb/onlinedocs/gdb.html].
;Learning C tutorials
The Python language implementation is written in the C programming language.
*[http://c.learncodethehardway.org/book/ Learn C The Hard Way]
*[http://www.learn-c.org/ Learn C the free interactive C tutorial.]
*[https://learncodethehardway.org/c/ Learn C The Hard Way] ($)
1,969
edits

Navigation menu