jrfonseca / drmingw

Postmortem debugging tools for MinGW.
GNU Lesser General Public License v2.1
273 stars 53 forks source link

The reading debug symbols from external files doesn't works. Possible regression. #12

Closed dismine closed 9 years ago

dismine commented 9 years ago

Hi.

I checked with version 0.7.2. And it again doesn't work.

#include <Windows.h>
#include <string>
class Test
{
public:
    Test();
    int length() const;
private:
    int size;
};
Test::Test() 
    :size(0)
{}
inline int Test::length() const
{ 
    return size; 
}
int main()
{
    LoadLibraryA("exchndl.dll");
    std::string *a;
    a = NULL;
    *a += "pi is " + std::to_string(3.1415926);
    return(0);
} 

Build with g++ -g -std=c++0x main.cpp -o test.exe

Strip with objcopy --only-keep-debug test.exe test.dbg objcopy --strip-debug test.exe objcopy --add-gnu-debuglink="test.dbg" test.exe

Report without strip

Error occured on воскресенье, мая 10, 2015 at 17:45:03. test.exe caused an Access Violation at location 6FC8AAA6 in module libstdc++-6.dll Reading from location 00000000. Registers: eax=00000000 ebx=00000000 ecx=003e4ea4 edx=0022fed4 esi=0022fed4 edi=00000011 eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202 AddrPC Params 6FC8AAA6 0022FED8 00409078 00000000 libstdc++-6.dll!ZNSs6appendERKSs 0040788C 0022FED4 00409078 0022FED8 test.exe!operator+<char, std::char_traits, std::allocator > [C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h @ 2475] 2473: operator+(const _CharT* lhs, 2474: basic_string<_CharT, _Traits, _Alloc>&& rhs)

2475: { return std::move(rhs.insert(0, lhs)); } 2476: 2477: template<typename _CharT, typename _Traits, typename _Alloc> 004016BA 003E3998 00000011 00000001 test.exe!main [C:\test/main.cpp @ 27] 25: std::string a; 26: a = NULL; 27: a += "pi is " + std::to_string(3.1415926); 28: return(0); 29: } 004013DE 00380039 00340034 7FFD6000 test.exe!__tmainCRTStartup 7C817077 004014E0 00000000 78746341 kernel32.dll!BaseProcessStart

Report with strip

Error occured on воскресенье, мая 10, 2015 at 17:46:02. test.exe caused an Access Violation at location 6FC8AAA6 in module libstdc++-6.dll Reading from location 00000000. Registers: eax=00000000 ebx=00000000 ecx=003e4ea4 edx=0022fed4 esi=0022fed4 edi=00000011 eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0 nv up ei pl nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202 AddrPC Params 6FC8AAA6 0022FED8 00409078 00000000 libstdc++-6.dll!ZNSs6appendERKSs 0040788C 0022FED4 00409078 0022FED8 test.exe!std::basic_string<char, std::char_traits, std::allocator > std::operator+<char, std::char_traits, std::allocator >(char const*, std::basic_string<char, std::char_traits, std::allocator >&&) 004016BA 003E3998 00000011 00000001 test.exe!main 004013DE 00380039 00340034 7FFDB000 test.exe!__tmainCRTStartup 7C817077 004014E0 00000000 78746341 kernel32.dll!BaseProcessStart

How always i used all dll's.

renatosilva commented 9 years ago

I confirm the problem, but did .gnu_debuglink ever work for anyone? I tried 0.6.6 and above without success.

strixcode commented 9 years ago

I also confirm the issue. .gnu_debuglink worked for me with version 0.6.2 as far as I remember. I'm not sure if the bug is in DrMinGW or in gcc/objcopy version for Windows.

jrfonseca commented 9 years ago

I can't repro on my system. It works just fine:

z:\projects\drmingw\issues\12>g++ --version
g++ (GCC) 4.8.3
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

z:\projects\drmingw\issues\12>g++ -g -std=c++0x main.cpp -o test.exe

z:\projects\drmingw\issues\12>objcopy --only-keep-debug test.exe test.dbg

z:\projects\drmingw\issues\12>objcopy --strip-debug test.exe

z:\projects\drmingw\issues\12>objcopy --add-gnu-debuglink="test.dbg" test.exe

z:\projects\drmingw\issues\12>copy /y drmingw-0.7.2-win32\bin\exchndl.dll .
        1 file(s) copied.

z:\projects\drmingw\issues\12>copy /y drmingw-0.7.2-win32\bin\symsrv.yes .
        1 file(s) copied.

z:\projects\drmingw\issues\12>copy /y drmingw-0.7.2-win32\bin\symsrv.dll .
        1 file(s) copied.

z:\projects\drmingw\issues\12>copy /y drmingw-0.7.2-win32\bin\mgwhelp.dll .
        1 file(s) copied.

z:\projects\drmingw\issues\12>copy /y drmingw-0.7.2-win32\bin\dbghelp.dll .
        1 file(s) copied.

z:\projects\drmingw\issues\12>del test.RPT
Could Not Find z:\projects\drmingw\issues\12\test.RPT

z:\projects\drmingw\issues\12>test.exe

z:\projects\drmingw\issues\12>type test.RPT
-------------------

Error occured on Thursday, June 4, 2015 at 10:25:27.

test.exe caused an Access Violation at location 6FC89887 in module libstdc++-6.dll Reading from location 00000000.

Registers:
eax=0028fe94 ebx=00000000 ecx=00000000 edx=00386fcc esi=00382ca8 edi=0000000e
eip=6fc89887 esp=0028fe10 ebp=0028fe38 iopl=0         nv up ei pl nz na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010202

AddrPC   Params
6FC89887 0028FE94 00409038 0028FE98  libstdc++-6.dll!ZNSs6appendERKSs
0040164D 00382C70 00000009 00000001  test.exe!main  [z:\projects\drmingw\issues\12/main.cpp @ 23]
    21:     std::string *a;
    22:     a = NULL;
>   23:     *a += "pi is " + std::to_string(3.1415926);
    24:     return(0);
    25: }
004013DE 7EFDE000 0028FFD4 779A9F72  test.exe!__tmainCRTStartup
7660338A 7EFDE000 938A7145 00000000  kernel32.dll!BaseThreadInitThunk
779A9F72 004014E0 7EFDE000 00000000  ntdll.dll!__RtlUserThreadStart
779A9F45 004014E0 7EFDE000 00000000  ntdll.dll!_RtlUserThreadStart

Those who repro the issue, could you please tell me:

dismine commented 9 years ago

Those who repro the issue, could you please tell me:

  • exact mingw version you have (and where you got it from)
  • Windows version

If you will careful look into my report you will find string C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32. So my mingw is part of Qt 5.4.1.

And i used Windows XP.

Hope it will help.

jrfonseca commented 9 years ago

So my mingw is part of Qt 5.4.1.

That's it. I also happened to have that installed, and indeeds it repros fine with it.

dismine commented 9 years ago

z:\projects\drmingw\issues\12>g++ --version g++ (GCC) 4.8.3 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My mingw version is:

C:\test>g++ --version
g++ (i686-posix-dwarf-rev2, Built by MinGW-W64 project) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
dismine commented 9 years ago

I also confirm the issue. .gnu_debuglink worked for me with version 0.6.2 as far as I remember. I'm not sure if the bug is in DrMinGW or in gcc/objcopy version for Windows.

For me it worked in 0.6.3 too.

dismine commented 9 years ago

My research

drmingw-0.6.3-win32

Report without strip

-------------------

Error occured on Thursday, June 4, 2015 at 18:47:15.

C:\test\test.exe caused an Access Violation at location 6FC8AAA6 in module C:\test\libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4d14 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)  [C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h @ 2475]
004016BA 003E3998 00000011 00000001  test.exe!main  [C:\test/main.cpp @ 27]
004013DE 00380039 00340034 7FFD4000  test.exe!13de
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

Report with strip

-------------------

Error occured on Thursday, June 4, 2015 at 18:47:51.

C:\test\test.exe caused an Access Violation at location 6FC8AAA6 in module C:\test\libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4d14 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)  [C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h @ 2475]
004016BA 003E3998 00000011 00000001  test.exe!main  [C:\test/main.cpp @ 27]
004013DE 00380039 00340034 7FFD5000  test.exe!13de
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

drmingw-0.6.4-win32

Should be broken.

drmingw-0.6.5-win32

Should be broken.

drmingw-0.6.6-win32

Report without strip

-------------------

Error occured on Thursday, June 4, 2015 at 18:23:49.

C:\test\test.exe caused an Access Violation at location 6FC8AAA6 in module C:\test\libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4d14 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!operator+<char, std::char_traits<char>, std::allocator<char> >  [C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h @ 2475]
004016BA 003E3998 00000011 00000001  test.exe!main  [C:\test/main.cpp @ 27]
004013DE 00380039 00340034 7FFD7000  test.exe!13de
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

Report with strip

-------------------

Error occured on Thursday, June 4, 2015 at 18:26:43.

C:\test\test.exe caused an Access Violation at location 6FC8AAA6 in module C:\test\libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4d14 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!788c
004016BA 003E3998 00000011 00000001  test.exe!16ba
004013DE 00380039 00340034 7FFDE000  test.exe!13de
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

drmingw-0.7.0-win32

Works broken on Windows XP

Report without strip

-------------------

Error occured on четверг, июня 4, 2015 at 18:33:07.

Report with strip

-------------------

Error occured on четверг, июня 4, 2015 at 18:33:51.

drmingw-0.7.1-win32

Report without strip

-------------------

Error occured on четверг, июня 4, 2015 at 18:35:16.

test.exe caused an Access Violation at location 6FC8AAA6 in module libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4ea4 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!operator+<char, std::char_traits<char>, std::allocator<char> >  [C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h @ 2475]
    ...
        operator+(const _CharT* __lhs,
          basic_string<_CharT, _Traits, _Alloc>&& __rhs)
>       { return std::move(__rhs.insert(0, __lhs)); }

      template<typename _CharT, typename _Traits, typename _Alloc>
    ...

004016BA 003E3998 00000011 00000001  test.exe!main  [C:\test/main.cpp @ 27]
    ...
    std::string *a;
    a = NULL;
>   *a += "pi is " + std::to_string(3.1415926);
    return(0);
    }
    ...

004013DE 00380039 00340034 7FFD9000  test.exe!__tmainCRTStartup
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

Report with strip

-------------------

Error occured on четверг, июня 4, 2015 at 18:36:05.

test.exe caused an Access Violation at location 6FC8AAA6 in module libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4ea4 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)
004016BA 003E3998 00000011 00000001  test.exe!main
004013DE 00380039 00340034 7FFD9000  test.exe!__tmainCRTStartup
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

drmingw-0.7.2-win32

Report without strip

-------------------

Error occured on четверг, июня 4, 2015 at 18:41:54.

test.exe caused an Access Violation at location 6FC8AAA6 in module libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4ea4 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!operator+<char, std::char_traits<char>, std::allocator<char> >  [C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h @ 2475]
  2473:     operator+(const _CharT* __lhs,
  2474:       basic_string<_CharT, _Traits, _Alloc>&& __rhs)
> 2475:     { return std::move(__rhs.insert(0, __lhs)); }
  2476: 
  2477:   template<typename _CharT, typename _Traits, typename _Alloc>
004016BA 003E3998 00000011 00000001  test.exe!main  [C:\test/main.cpp @ 27]
    25: std::string *a;
    26: a = NULL;
>   27: *a += "pi is " + std::to_string(3.1415926);
    28: return(0);
    29: }
004013DE 00380039 00340034 7FFDF000  test.exe!__tmainCRTStartup
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

Report with strip

-------------------

Error occured on четверг, июня 4, 2015 at 18:42:59.

test.exe caused an Access Violation at location 6FC8AAA6 in module libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4ea4 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)
004016BA 003E3998 00000011 00000001  test.exe!main
004013DE 00380039 00340034 7FFDA000  test.exe!__tmainCRTStartup
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart
dismine commented 9 years ago

It is little bit strange for me, but your report is

z:\projects\drmingw\issues\12>type test.RPT
-------------------

Error occured on Thursday, June 4, 2015 at 10:25:27.

test.exe caused an Access Violation at location 6FC89887 in module libstdc++-6.dll Reading from location 00000000.

Registers:
eax=0028fe94 ebx=00000000 ecx=00000000 edx=00386fcc esi=00382ca8 edi=0000000e
eip=6fc89887 esp=0028fe10 ebp=0028fe38 iopl=0         nv up ei pl nz na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010202

AddrPC   Params
6FC89887 0028FE94 00409038 0028FE98  libstdc++-6.dll!ZNSs6appendERKSs
0040164D 00382C70 00000009 00000001  test.exe!main  [z:\projects\drmingw\issues\12/main.cpp @ 23]
    21:     std::string *a;
    22:     a = NULL;
>   23:     *a += "pi is " + std::to_string(3.1415926);
    24:     return(0);
    25: }
004013DE 7EFDE000 0028FFD4 779A9F72  test.exe!__tmainCRTStartup
7660338A 7EFDE000 938A7145 00000000  kernel32.dll!BaseThreadInitThunk
779A9F72 004014E0 7EFDE000 00000000  ntdll.dll!__RtlUserThreadStart
779A9F45 004014E0 7EFDE000 00000000  ntdll.dll!_RtlUserThreadStart

different then my

-------------------

Error occured on четверг, июня 4, 2015 at 18:41:54.

test.exe caused an Access Violation at location 6FC8AAA6 in module libstdc++-6.dll Reading from location 00000000.

Registers:
eax=00000000 ebx=00000000 ecx=003e4ea4 edx=0022fed4 esi=0022fed4 edi=00000011
eip=6fc8aaa6 esp=0022fe90 ebp=0000000e iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202

AddrPC   Params
6FC8AAA6 0022FED8 00409078 00000000  libstdc++-6.dll!ZNSs6appendERKSs
0040788C 0022FED4 00409078 0022FED8  test.exe!operator+<char, std::char_traits<char>, std::allocator<char> >  [C:/Qt/Qt5.4.1/Tools/mingw491_32/i686-w64-mingw32/include/c++/bits/basic_string.h @ 2475]
  2473:     operator+(const _CharT* __lhs,
  2474:       basic_string<_CharT, _Traits, _Alloc>&& __rhs)
> 2475:     { return std::move(__rhs.insert(0, __lhs)); }
  2476: 
  2477:   template<typename _CharT, typename _Traits, typename _Alloc>
004016BA 003E3998 00000011 00000001  test.exe!main  [C:\test/main.cpp @ 27]
    25: std::string *a;
    26: a = NULL;
>   27: *a += "pi is " + std::to_string(3.1415926);
    28: return(0);
    29: }
004013DE 00380039 00340034 7FFDF000  test.exe!__tmainCRTStartup
7C817077 004014E0 00000000 78746341  kernel32.dll!BaseProcessStart

You have only one place in report and i have two.

jrfonseca commented 9 years ago

Thanks for the updates.

I believe found the bug. I should have a fix pushed, maybe later today.

For the record, earlier versions of DrMingw happened to support .gnu_debuglink because it was falling back to the GNU BFD library. But DrMingw's dependency on BFD was severed due to its license (GPL) which is fine for DrMingw itself, but less so for ExcHndl.

jrfonseca commented 9 years ago

You have only one place in report and i have two.

@dismine I also see two with Qt's binaries. It depends on the particular libstdc++ version/implementation.

renatosilva commented 9 years ago

I confirm that latest revision 749fca8 does not reproduce the bug anymore:

Error occured on quinta-feira, junho 4, 2015 at 19:42:58.

pidgin.exe caused an Access Violation at location 6C4DF75E in module pidgin.dll Writing to location 00000000.

Registers:
eax=00000000 ebx=0649b7e0 ecx=00000000 edx=6c4df750 esi=00000000 edi=0028e870
eip=6c4df75e esp=0028e6f0 ebp=0028e81c iopl=0         nv up ei pl zr na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010246

AddrPC   Params
6C4DF75E 00000001 00000001 00000004  pidgin.dll!modify_account_cb  [D:\Pidgin\build\pidgin.32\pidgin/gtkblist.c @ 8012]
  8010: {
  8011:     int *x = NULL;
> 8012:     *x = 1;
  8013:     pidgin_account_dialog_show(PIDGIN_MODIFY_ACCOUNT_DIALOG, data);
  8014: }