Bug 29548 - Can't breakpoint __cxa_throw with Qt5Core.dll
Summary: Can't breakpoint __cxa_throw with Qt5Core.dll
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: 11.1
: P2 normal
Target Milestone: 15.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-09-05 16:36 UTC by Denis Zinin
Modified: 2023-12-05 17:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Denis Zinin 2022-09-05 16:36:22 UTC
Windows 10. Debugged binary compiled with C++ 12.2.0 under MSYS2/Mingw64.

I can't set breakpoint on throwing exception (__cxa_throw) in Clion bundled gdb 12.1. The same problem with Mingw64 GDB 12.1 and Mingw64 GDB 11.1.

But all work with Mingw64 GDB 10.1.

On starting gdb:
---------------
GNU gdb (GDB; JetBrains IDE bundle; build 152) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Function "swift_willThrow" not defined.
Function "_CxxThrowException" not defined.
Function "swift_errorRetain" not defined.
unset env HOME
---------------

I see suspicious "not defined".

But the real problem in the following.

In non working bundled gdb 12.1:
--------------------------------
(gdb) info symbol __cxa_throw
__cxa_throw in section .text of C:\Users\Veter\Desktop\Dev\_src\robo_003\cmake-build-debug\robo_001.exe
(gdb) info functions __cxa_throw
All functions matching regular expression "__cxa_throw":
Non-debugging symbols:
0x00007ff76b112108 __cxa_throw
0x00007ffe67a75f68 __cxa_throw_bad_array_new_length
0x00007ffe67a75f70 __cxa_throw
(gdb) info symbol 0x00007ff76b112108
__cxa_throw in section .text of C:\Users\Veter\Desktop\Dev\_src\robo_003\cmake-build-debug\robo_001.exe
(gdb) info symbol 0x00007ffe67a75f70
__cxa_throw in section .text of C:\Users\Veter\Desktop\Dev\robo\Qt5Core.dll
(gdb) break __cxa_throw
Function "__cxa_throw" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
Breakpoint is not set.
-------------------------------

In working external Mingw64 gdb 10.1. Same exe and libraries:
-------------------------------
(gdb) info symbol __cxa_throw
__cxa_throw in section .text of C:\Users\Veter\Desktop\Dev\_src\robo_003\cmake-build-debug\robo_001.exe
(gdb) info functions __cxa_throw
All functions matching regular expression "__cxa_throw":
Non-debugging symbols:
0x00007ffe670e5f68 __cxa_throw_bad_array_new_length
0x00007ffe670e5f70 __cxa_throw
(gdb) info symbol 0x00007ffe670e5f70
__cxa_throw in section .text of C:\Users\Veter\Desktop\Dev\robo\Qt5Core.dll
(gdb) break __cxa_throw
Note: breakpoint 2 also set at pc 0x7ffe670e5f70.
Note: breakpoint 2 also set at pc 0x7ff76b112108.
Breakpoint 7 at 0x7ff76b112108 (2 locations)
(gdb) info symbol 0x7ff76b112108
__cxa_throw in section .text of C:\Users\Veter\Desktop\Dev\_src\robo_003\cmake-build-debug\robo_001.exe
Breakpoint is set successfully.
--------------------------------

Simple project to reproduce the problem.

CMakeLists.txt:
-----------------------------------
cmake_minimum_required(VERSION 3.23)
project(untitled1)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets REQUIRED)
include_directories(${Qt5Widgets_INCLUDES})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")

add_executable(untitled1 main.cpp)

target_link_libraries (untitled1 ${Qt5Widgets_LIBRARIES})
---------------------------------------

main.cpp:
------------------
#include <iostream>
#include <QtCore/QString>
#include <QApplication>
#include <QtWidgets>
#include <QObject>
class MainWindow : public QMainWindow {
    Q_OBJECT

    public:
        explicit MainWindow() {};
        ~MainWindow() override {};


    };
#include "main.moc"

int main(int argc, char *argv[]) {
    std::cout << "Hello, World!" << std::endl;

    QApplication app(argc, argv);
    QCoreApplication::setApplicationName("robot");
    QCoreApplication::setOrganizationName("Figvam");

    MainWindow mainWin{};
    mainWin.show();

    throw std::exception();

    return QApplication::exec();

}
-------------------------

Without Qt5 all work well.

It seems the problem that "(gdb)info functions __cxa_throw" return twice __cxa_throw.

One from main binary, another from Qt5Core.dll.
-----------------------------------
(gdb) info functions __cxa_throw
All functions matching regular expression "__cxa_throw":
Non-debugging symbols:
0x00007ff76b112108 __cxa_throw
0x00007ffe67a75f68 __cxa_throw_bad_array_new_length
0x00007ffe67a75f70 __cxa_throw
------------------------------------

But in old gdb it return only one __cxa_throw.

"catch throw" is not resolve the problem. It's output: "Catchpoint 7 (throw)" But on real throw program exited (not pause) with: [Thread 42504.0x7adc exited with code 3] [Inferior 1 (process 42504) exited with code 03]".
Comment 1 Sourceware Commits 2023-12-05 17:47:32 UTC
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6e28dd6fa3027d38351d2cf672509eca05aa19fd

commit 6e28dd6fa3027d38351d2cf672509eca05aa19fd
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Tue Dec 5 18:41:44 2023 +0100

    Fix breakpoints on symbols with multiple trampoline symbols
    
    On mingw targets it's possible that there are multiple trampoline
    symbols for __cxa_throw, in each module where a throw is done, but
    without a corresponding global symbol.
    Since commit 77f2120b200be6cabbf6f610942fc1173a8df6d3 they cancel each
    other out in search_minsyms_for_name, which makes it impossible to set
    a breakpoint there:
    
    (gdb) b __cxa_throw
    Function "__cxa_throw" not defined.
    Make breakpoint pending on future shared library load? (y or [n]) y
    Breakpoint 2 (__cxa_throw) pending.
    (gdb) c
    Continuing.
    [Inferior 1 (process 10004) exited with code 03]
    
    With catch throw it also doesn't work, and you don't even get an error
    message:
    
    (gdb) catch throw
    Catchpoint 2 (throw)
    (gdb) c
    Continuing.
    [Inferior 1 (process 5532) exited with code 03]
    (gdb)
    
    The fix is to simply ignore other trampoline symbols when looking for
    corresponding global symbols, and it's working as expected:
    
    (gdb) b __cxa_throw
    Breakpoint 2 at 0x13f091590 (2 locations)
    (gdb) c
    Continuing.
    
    Breakpoint 2.1, 0x000000013f091590 in __cxa_throw ()
    (gdb)
    
    And catch throw also works again:
    
    (gdb) catch throw
    Catchpoint 2 (throw)
    (gdb) c
    Continuing.
    
    Catchpoint 2.1 (exception thrown), 0x000000013f181590 in __cxa_throw ()
    (gdb)
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29548
    Approved-By: Tom Tromey <tom@tromey.com>
Comment 2 Hannes Domani 2023-12-05 17:49:29 UTC
Fixed.