GDB index cache for faster debugging

Developing LibreOffice requires debugging. But, with the default settings, it takes a long time to load GDB and use it. Here I discuss GDB index cache to improve the debugging experience with a faster startup.

GDB Debugging

Whether you want to fix a bug or add a feature to LibreOffice, debugging is an essential part of the task. Running LibreOffice in debug mode, going step by step and checking the value of a variable and checking the stack trace and threads is among the thing that developers do in a debug session.

But, if you have ever tried to debug LibreOffice using GDB, you may have noticed the big delay before you can use LibreOffice in a debug session.

To start a debug session, you need to have a working build environment for LibreOffice. Then, invoke:

$ make debugrun

You will see a few things written on the screen, and then gdb prompt. Enter run to run LibreOffice, after setting the VCL plugin to gen, which starts faster:

(gdb) set env SAL_USE_VCLPLUGIN=gen
(gdb) run

It may even take something like 30 seconds or more before you see LibreOffice running. But, there are ways to improve the situation, and GDB index caching is one of them.

To benchmark the required time for startup and shutdown of Writer, you may set OOO_EXIT_POST_STARTUP environment variable to 1:

(gdb) set env SAL_USE_VCLPLUGIN=gen
(gdb) set OOO_EXIT_POST_STARTUP=1
(gdb) run --writer

In this way, LibreOffice exits immediately after startup. Further environment variables are listed in TDF Wiki:

GDB Index Caching

GDB needs to read symbol files to create its internal symbols, and provide symbols while you debug instead of simple memory addresses. That requires scanning of many files, and increases startup time. In order to improve that, GDB can automatically cache symbol indexes for a faster next startups.

Using this feature requires at least GDB 8.3, which is usually true in recent Linux distributions.

Suggested Configuration

This is a suggested configuration file for GDB, which you may store in ~/.config/gdb/gdbinit:

add-auto-load-safe-path ~/core/instdir
add-auto-load-safe-path ~/core/workdir
set print pretty on
set debuginfod enabled off
set index-cache enabled on

It enables index caching, alongside pretty printing, and some related scripts in instdir/ and workdir/, and it disables fetching debug symbols from internet through debuginfod.

Checking the GDB Index Cache Status

To check the status of caching, first start a debug session:

$ make debugrun

Then, invoke this command in the GDB prompt:

show index-cache directory

show index-cache stats

This will show you the cache directory, and the statistics, which will be useful only after a debug session, to asses the number of cache hits and misses.

gdb index cache status
gdb index cache status

You may check the size of the cache:

$ du -hs ~/.cache/gdb/

Please be aware that there is no limit for the size of GDB cache, therefore it may grow over time. You may remove the cache, and it will be re-created after first use, which is a cold start. The next debug sessions will start faster, as the cache is already built.

Final Notes

Debugging is an essential part of LibreOffice development, but it has its own tips and tricks. If you want to get better debugging experience, make sure that you tune your debugging environment and read a few notes for improving your debug session. This is one of the previous posts on debugging LibreOffice:

Debugging tips for LibreOffice

Written by:

Hossein is the Developer Community Architect for The Document Foundation (TDF).
View All Posts
Follow Me :

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy