"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does GDB Report a Missing File Error When Debugging C++ Exceptions in Ubuntu?

Why Does GDB Report a Missing File Error When Debugging C++ Exceptions in Ubuntu?

Published on 2024-11-14
Browse:605

Why Does GDB Report a Missing File Error When Debugging C   Exceptions in Ubuntu?

GDB Displays Missing File Error for Library Source Code

When using GDB to debug C exceptions, users may encounter an error message indicating a missing file, such as "No such file or directory" for "raise.c." This error can occur even if the exception is handled correctly.

Solution: Obtain Library Source Code and Debug Information

To address this issue, it is necessary to obtain the source code and debug information for the relevant library, in this case, libc6. Ubuntu provides the debuginfo package for this purpose.

Steps to Debugging C Library Source Code:

  1. Install the debuginfo version of libc6: sudo apt install libc6-dbg.
  2. Configure the package system to download source code packages:

    • Install dpkg-dev: sudo apt install dpkg-dev.
    • Uncomment "deb-src" lines in /etc/apt/sources.list if necessary.
  3. Download source code:

    • Create a directory: /opt/src.
    • Download source code: apt source libc6.
    • Note the source code directory (e.g., /opt/src/glibc-2.23).
  4. Adjust GDB's source code directory:

    • Identify the expected source code directory using (gdb) info source.
    • Move or symlink the source code to the expected location, or set a substitute path: (gdb) set substitute-path /expected-location /actual-location.

Once these steps are completed, GDB will be able to access the correct source code and provide accurate debugging information for the exception.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3