Bonjour � tous!
Apr�s si longtemps loin de nos chers forums, me voici de retour avec un probl�me assez coriace.

J'ai un programme pour Windows qui fonctionne bien en temps normal:
  • Son manifeste exige les droits d'administrations, et windows s'assure qu'il soit lanc� avec.
  • Son IHM Qt s'affiche, je peux int�ragir avec,
  • L'acc�s au p�riph�rique usb essentiel au travail se fait correctement,
  • etc

Quand j'ouvre une console admin et le lance directement, sans argument, tout se passe bien.
Par contre, si je le lance dans un gdbserver, je rencontre une segfault syst�matiquement, et avant main.

Je s�che compl�tement, sans une once de piste. Auriez-vous une id�e?

Un peu de contexte plus pr�cis.
Le soft est compil� pour un windows 10, mais depuis un environnement docker linux: un ubuntu 20.04 avec entre autre les paquets officiel mingw et gdb-mingw-w64 et gdb-mingw-w64-target.
La compilation est pilot�e par CMake,
Qt est compil� en biblioth�ques statiques dans le m�me docker.
Le programme est li� avec -static-libstdc++ -static-libgcc
Le programme est compil� en debug (incluant -g -ggdb)

La proc�dure de d�bug concr�te:
  1. Entrer dans le docker
  2. Compiler le soft sur le pc cible, dans un dossier vide, (Normalement il est sans d�pendance).
  3. copier aussi /usr/share/win32/gdbserver.exe, ainsi que ses d�pendances, /usr/lib/gcc/i686-w64-mingw32/*-win32/lib{stdc++*.dll,gcc_s*.dll}
  4. sur le pc cible ouvrir une console avec droit d'admin et cd dans le dit dossier
  5. gdbserver.exe <une ip>:3636 Programme.exe
  6. gdbserver se lance, affiche qu'il attends une connexion.
  7. Sur le pc de build, toujours dans le docker, lancer i686-w64-mingw32-gdb Programme.exe
  8. quand le binaire est charg� (pour les symboles de d�bug), target remote <ip du pc window>:3636
  9. gdb charge les dlls windows.
  10. continue
  11. la segfault se produit syst�matiquement.

Si en 5) je fais juste Programme.exe tout se passe bien.

gdb affiche
$ i686-w64-mingw32-gdb Programme.exe 
Reading symbols from Programme.exe...
(gdb) target remote <ip windows>:3636
Remote debugging using <ip windows>:3636
Reading C:/WINDOWS/SYSTEM32/ntdll.dll from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading C:/WINDOWS/System32/kernel32.dll from remote target...
Reading C:/WINDOWS/System32/KernelBase.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/apphelp.dll from remote target...
Reading C:/WINDOWS/System32/advapi32.dll from remote target...
Reading C:/WINDOWS/System32/msvcrt.dll from remote target...
Reading C:/WINDOWS/System32/sechost.dll from remote target...
Reading C:/WINDOWS/System32/rpcrt4.dll from remote target...
Reading C:/WINDOWS/System32/sspicli.dll from remote target...
Reading C:/WINDOWS/System32/cryptbase.dll from remote target...
Reading C:/WINDOWS/System32/bcryptprimitives.dll from remote target...
Reading C:/WINDOWS/System32/gdi32.dll from remote target...
Reading C:/WINDOWS/System32/win32u.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/FWPUCLNT.DLL from remote target...
Reading C:/WINDOWS/SYSTEM32/dsound.dll from remote target...
Reading C:/WINDOWS/System32/gdi32full.dll from remote target...
Reading C:/WINDOWS/System32/bcrypt.dll from remote target...
Reading C:/WINDOWS/System32/msvcp_win.dll from remote target...
Reading C:/WINDOWS/System32/powrprof.dll from remote target...
Reading C:/WINDOWS/System32/ucrtbase.dll from remote target...
Reading C:/WINDOWS/System32/umpdc.dll from remote target...
Reading C:/WINDOWS/System32/user32.dll from remote target...
Reading C:/WINDOWS/System32/combase.dll from remote target...
Reading C:/WINDOWS/System32/imm32.dll from remote target...
Reading C:/WINDOWS/System32/ole32.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/winmm.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/IPHLPAPI.DLL from remote target...
Reading C:/WINDOWS/System32/oleaut32.dll from remote target...
Reading C:/WINDOWS/System32/shell32.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/winmmbase.dll from remote target...
Reading C:/WINDOWS/System32/cfgmgr32.dll from remote target...
Reading C:/WINDOWS/System32/SHCore.dll from remote target...
Reading C:/WINDOWS/System32/windows.storage.dll from remote target...
Reading C:/WINDOWS/System32/profapi.dll from remote target...
Reading C:/WINDOWS/System32/shlwapi.dll from remote target...
Reading C:/WINDOWS/System32/kernel.appcore.dll from remote target...
Reading C:/WINDOWS/System32/cryptsp.dll from remote target...
Reading C:/WINDOWS/System32/ws2_32.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/WinSCard.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/wininet.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/wsock32.dll from remote target...
Reading C:/WINDOWS/SYSTEM32/devobj.dll from remote target...
0x7778eaa3 in ntdll!LdrInitShimEngineDynamic () from target:C:/WINDOWS/SYSTEM32/ntdll.dll

(gdb) continue
Continuing.

Thread 1 received signal SIGSEGV, Segmentation fault.
0x6d157d0b in WinSCard!SCardCancel () from target:C:/WINDOWS/SYSTEM32/WinSCard.dll
(gdb) bt
#0  0x6d157d0b in WinSCard!SCardCancel () from target:C:/WINDOWS/SYSTEM32/WinSCard.dll
#1  0x6d15bf2a in WinSCard!ClassInstall32 () from target:C:/WINDOWS/SYSTEM32/WinSCard.dll
#2  0x6d153758 in ?? () from target:C:/WINDOWS/SYSTEM32/WinSCard.dll
#3  0x6d1578ea in WinSCard!SCardCancel () from target:C:/WINDOWS/SYSTEM32/WinSCard.dll
#4  0x6d15712d in WinSCard!SCardCancel () from target:C:/WINDOWS/SYSTEM32/WinSCard.dll
#5  0x77751de6 in ntdll!RtlFreeUserStack () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#6  0x77715608 in ntdll!RtlGetNtSystemRoot () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#7  0x6d156ff0 in WinSCard!SCardCancel () from target:C:/WINDOWS/SYSTEM32/WinSCard.dll
#8  0x77723f8f in ntdll!RtlCompareUnicodeStrings () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#9  0x77724836 in ntdll!RtlMultiByteToUnicodeSize () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#10 0x7772484d in ntdll!RtlMultiByteToUnicodeSize () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#11 0x77789542 in ntdll!RtlCaptureStackContext () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#12 0x77789382 in ntdll!RtlCaptureStackContext () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#13 0x77731dd1 in ntdll!LdrInitializeThunk () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#14 0x77731cc1 in ntdll!LdrInitializeThunk () from target:C:/WINDOWS/SYSTEM32/ntdll.dll
#15 0x00000000 in ?? ()
(gdb) 
WinSCard est un module du runtime de windows, qui permet d'acc�der aux "smart cards", qui est mon mat�riel essentiel (une sorte de carte � puce)

Fait amusant, je peux faire un continue, et le main commence alors, la v�rification des arguments de ligne de commande est faite, puis j'aurai une boucle infinie qui se cr�e, vers la cr�ation de l'IHM.

Autres informations possiblement pertinente:
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ i686-w64-mingw32-gdb -v
GNU gdb (GDB) 9.1
Copyright (C) 2020 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.
 
$ i686-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/9.3-win32/lto-wrapper
Target: i686-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libdir='/usr/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --with-headers=/usr/i686-w64-mingw32/include --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --enable-threads=win32 --program-suffix=-win32 --program-prefix=i686-w64-mingw32- --target=i686-w64-mingw32 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld --enable-libatomic --enable-libstdcxx-filesystem-ts=yes --enable-dependency-tracking
Thread model: win32
gcc version 9.3-win32 20200320 (GCC)

CMake utilise les flags de compilation suivant:
Code makefile : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16
 
# compile CXX with /usr/lib/ccache/i686-w64-mingw32-g++
# compile RC with i686-w64-mingw32-windres
CXX_FLAGS = -g -ggdb   -Wall -Wextra -Wctor-dtor-privacy -Woverloaded-virtual -Wold-style-cast -Wformat -Wformat-security -Werror=format-security -Wuninitialized -Winit-self -Wpointer-arith -fno-stack-protector -DDEBUG -D__STDC_FORMAT_MACROS -std=c++11
 
CXX_DEFINES = -DNOMINMAX -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_STATICPLUGIN -DQT_WIDGETS_LIB -DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0601
 
CXX_INCLUDES = @CMakeFiles/Programme.dir/includes_CXX.rsp
 
RC_FLAGS =   -DDEBUG -D__STDC_FORMAT_MACROS
 
RC_DEFINES = -DCRYPTOSMART_TYPES_TEST_SUPPORT -DNOMINMAX -DNO_DRIVERLESS -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_STATICPLUGIN -DQT_WIDGETS_LIB -DSDK_TEST_SUPPORT -DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0601
 
RC_INCLUDES = -I~/Programe/build_windows_debug -I~/Programe -I~/Programe/build_windows_debug/Programme_autogen/include -I~/Programe/include -I~/Programe/include/Widgets -I~/artifacts/sdk-client/windows/debug/include -I~/artifacts/External/windows/debug/include/mbedtls-2.16 -I/opt/qt-win32-release-static/include -I/opt/qt-win32-release-static/include/QtWidgets -I/opt/qt-win32-release-static/include/QtGui -I/opt/qt-win32-release-static/include/QtCore -I/opt/qt-win32-release-static/./mkspecs/win32-g++ -I/opt/qt-win32-release-static/include/QtNetwork
Code makefile : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#CMakeFiles/Programme.dir/includes_CXX.rsp
-I~/Programme/build_windows_debug
-I~/Programme
-I~/Programme/build_windows_debug/Programme_autogen/include
-I~/Programme/include
-I~/Programme/include/Widgets
-isystem ~/artifacts/sdk-client/windows/debug/include
-isystem ~/artifacts/External/windows/debug/include/mbedtls-2.16
-isystem /opt/qt-win32-release-static/include
-isystem /opt/qt-win32-release-static/include/QtWidgets
-isystem /opt/qt-win32-release-static/include/QtGui
-isystem /opt/qt-win32-release-static/include/QtCore
-isystem /opt/qt-win32-release-static/./mkspecs/win32-g++
-isystem /opt/qt-win32-release-static/include/QtNetwork
L'�dition de lien:
Code bash : S�lectionner tout - Visualiser dans une fen�tre � part
/usr/lib/ccache/i686-w64-mingw32-g++ -g -ggdb  -static -mwindows -Wl,--whole-archive CMakeFiles/Programme.dir/objects.a -Wl,--no-whole-archive  -o Programme.exe -Wl,--out-implib,libProgramme.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/Programme.dir/linklibs.rsp
Code bash : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#linklibs.rsp
/opt/qt-win32-release-static/plugins/bearer/libqgenericbearer.a
/opt/qt-win32-release-static/plugins/bearer/libqnativewifibearer.a
/opt/qt-win32-release-static/plugins/platforms/libqwindows.a
/opt/qt-win32-release-static/lib/libQt5Widgets.a
/opt/qt-win32-release-static/lib/libQt5Network.a
/opt/qt-win32-release-static/lib/libQt5Gui.a
/opt/qt-win32-release-static/lib/libQt5Core.a
/opt/qt-win32-release-static/lib/libqtpcre.a
/opt/qt-win32-release-static/lib/libqtpng.a
/opt/qt-win32-release-static/lib/libqtharfbuzzng.a
/opt/qt-win32-release-static/lib/libQt5PlatformSupport.a
-limm32
-lopengl32
-liphlpapi
-lws2_32
-lrpcrt4
-lfwpuclnt
~/artifacts/sdk-client/windows/debug/lib/libSDK.a
~/artifacts/External/windows/debug/lib/libspeex.a
~/artifacts/External/windows/debug/lib/libpcre.a
~/artifacts/External/windows/debug/lib/libminizip.a
~/artifacts/External/windows/debug/lib/libzlib.a
-lwsock32
-lws2_32
-lwininet
-lwinmm
-ldsound
-lwinscard
-lksuser
-lwbemuuid
~/artifacts/External/windows/debug/lib/libsqlite.a
~/artifacts/External/windows/debug/lib/libmbedtls.a
-static-libgcc
-static-libstdc++
-static-libgcc
-static-libstdc++
/opt/qt-win32-release-static/lib/libqtmain.a
-lws2_32
-lrpcrt4
-lfwpuclnt
-lkernel32
-luser32
-lgdi32
-lwinspool
-lshell32
-lole32
-loleaut32
-luuid
-lcomdlg32
-ladvapi32