Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

How lazy debuginfo loading improves GDB and Valgrind

January 2, 2024
Aaron Merey
Related topics:
CompilersLinux
Related products:
Red Hat Enterprise Linux

Share:

    Debugging information, a.k.a debuginfo, relates the machine instructions in an executable or shared library with human-readable information from the binary's source files. This information includes the names of functions and variables as well as the source file and line numbers where these symbols are declared and referenced. Debuggers such as GDB, the GNU debugger, and profilers such as Valgrind use debuginfo to provide developers with richly detailed views into the occurrence of memory errors in a running process or the exact cause of a crash recorded in a core file. To learn more about debuginfo, check out the following articles: Debuginfo is not just for debugging programs and The GDB developer’s GNU Debugger tutorial Part 2.

    Debuginfod

    Debuginfo is very useful for developers but it can come with a few downsides. One problem is that it can be quite large. For example, libwebkitgtk debuginfo is well over 3 GB. Acquiring the precise version of a binary's debuginfo and having the necessary permissions to install it and make it available to your debugger can be inconvenient or even impossible, depending on your particular debugging environment.

    We developed the debuginfod tool for developer tools to automatically download the exact debuginfo files they require for maximally detailed debugging and profiling. Debuginfod is an HTTP file server and client library that enables tools to easily download debugging resources, including debuginfo and source files. Debugging tools, including GDB and Valgrind, can use Fedora's public debuginfod server to download the precise set of debuginfo and source files needed to debug or profile any executable packaged for Fedora since Fedora 32. Other Linux distributions also provide public debuginfod servers. Refer to the documentation for a complete list of supported distros. Debuginfod is part of the elfutils project. For more information, read my 2019 article introducing debuginfod.

    The problem with eagerly loading debuginfo

    A straightforward implementation of a debuginfod client for GDB and Valgrind simply downloads shared library debuginfo as soon as  each shared library is linked to the running process being debugged or referenced in a core file. However just because a shared library is linked doesn't mean that it's relevant to every debugging or profiling session. This eager downloading of debuginfo for every library associated with a process or core file can result in longer download times as well as wasted space taken up by the unnecessary debuginfo. This problem is also relevant even when the tool is not using debuginfod but is instead accessing debuginfo that has been installed locally. Decoding and reading all of the symbols, strings, addresses, etc. in every library's debuginfo can be time consuming. If this information is never used during the debugging or profiling session, then time was wasted. The extent and significance of this waste of time depends on factors such as the state of the debugged process, the size of all relevant debuginfo, the speed of your network, and the amount of available storage space, etc.

    Improving GDB and Valgrind with lazy debuginfo loading

    To improve the efficiency of debuginfo reading and downloading in GDB and Valgrind, we have been implementing lazy loading of debuginfo. In contrast to eager loading, lazy loading defers downloading or parsing debuginfo until the tool has a specific need to do so. GDB leverages debuginfod's ELF/DWARF section downloading to implement lazy loading. Instead of downloading a shared library's entire debuginfo file, GDB can instead download only the gdb-index section of the debuginfo. These indices contain information regarding the shared library's symbols that GDB can use until full debuginfo is actually needed. The size of these indices is around 7% of the size of the entire debuginfo file, so this can significantly reduce the total amount of debuginfo downloaded in a given debugging session.

    Here are a few comparisons of lazy loading download sizes to eager loading download sizes. Disclaimer: the following numbers can change depending on the exact versions of the executables and shared libraries involved, as well as debuginfo that you have already installed.

    • $ gdb -ex ‘break do_main’ -ex ‘run’ /usr/lib64/firefox/firefox
      • 94% reduction (235 MB vs 3.8 GB)
    • $ gdb -ex ‘backtrace’ --pid [/usr/bin/virt-manager process]
      • 82% reduction (57 MB vs 323 MB)
    • $ gdb --core libreoffice-writer.core
      • 87% reduction (204 MB vs 1.6 GB)
    • $ gdb -ex ‘run’ /usr/local/bin/gdb
      • 86% reduction (11 MB vs 80 MB)

    Valgrind's lazy loading implementation differs from GDB's by not requiring any indices. Valgrind simply postpones downloading and reading of shared library debuginfo until it needs specific address or symbol information from a shared library. There are cases where Valgrind ends up requiring debuginfo for most shared libraries linked to some process. In that case, the performance of eager and lazy loading will be similar. In these cases, we can at least be sure that Valgrind is actually making use of every debuginfo it downloads. In other cases, we see significant reductions in the amount of debuginfo downloaded with lazy loading.

    • $ valgrind /usr/bin/gnome-calendar
      • 94% reduction (279 MB vs 4.8 GB)
    • $ valgrind /usr/local/bin/gdb
      • 41% reduction (47 MB vs 80 MB)
    • $ valgrind /usr/bin/virt-manager
      • 15% reduction (273 MB vs 323 MB)

    Lazy loading is now supported in Valgrind since Fedora 37. GDB's lazy loading is currently in development and will be coming to Fedora once complete.

    Last updated: April 1, 2024

    Related Posts

    • Remote debugging with GDB

    • How to debug memory errors with Valgrind and GDB

    • The GDB developer's GNU Debugger tutorial, Part 1: Getting started with the debugger

    • Debuginfo is not just for debugging programs

    • Using Delve to debug Go programs on Red Hat Enterprise Linux

    • Exploring x86-64-v3 for Red Hat Enterprise Linux 10

    Recent Posts

    • How Trilio secures OpenShift virtual machines and containers

    • How to implement observability with Node.js and Llama Stack

    • How to encrypt RHEL images for Azure confidential VMs

    • How to manage RHEL virtual machines with Podman Desktop

    • Speech-to-text with Whisper and Red Hat AI Inference Server

    What’s up next?

    This cheat sheet presents a collection of Linux commands and executables for developers who are using the Linux operating system in advanced programming scenarios. 

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue