Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-23885

QtCreator doesn't display std::unique_ptr with custom destructors correctly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • Qt Creator 4.12.1
    • Qt Creator 4.11.2
    • Debugger
    • None
    • Windows 10, gcc 9.2.0, gdb 8.3.
      Arch Linux with KDE/X11, gcc 9.3.0, gdb 9.1.
    • All
    • 252a0431d126ea85a83b67ae266f2d3387d8bd0b

    Description

      Hello.

      Straight to the point.
      When I create std::unique_ptr like
      std::unique_ptr<my_data> p = std::unique_ptr<my_data>{new my_data};
      then I can see correct values of my_data struct in debugger view.
      But if I create std::unique_ptr with custom destructor, it doesn't show correct values.

      Code to reproduce:

      #include <memory>
      #include <cstring>
      
      struct foo
      {
        int a;
        double b;
        char c;
        char d[44];
        double * p;
      };
      
      using foo_ptr = std::unique_ptr<foo, void (*)(foo *)>;
      static foo * alloc_foo() { return new foo; }
      static void free_foo(foo * p) { delete p; }
      
      int main(int argc, char * argv[])
      {
        foo_ptr p = foo_ptr{alloc_foo(), free_foo};
        p->a = 10;
        p->b = 15.;
        p->c = 'a';
        memset(p->d, 0, sizeof(p->d));
        p->p = nullptr;
      }
      

      You need to set breakpoint to the last line of the code and check values of the `p` in the debugger view.
      I attached screenshot to illustrate the problem. There are right values at the bottom of debugger view and wrong at the top.

      My environment is Windows 10, gcc:

       Using built-in specs.
       COLLECT_GCC=gcc
       COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe
       Target: x86_64-w64-mingw32
       Configured with: ../gcc-9.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++ --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --enable-plugin --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=[https://sourceforge.net/projects/msys2] --with-gnu-as --with-gnu-ld
       Thread model: posix
       gcc version 9.2.0 (Rev2, Built by MSYS2 project)
      

      gdb:

       GNU gdb (GDB) 8.3
       Copyright (C) 2019 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.
      

      Also I tested it on Arch Linux. There is KDE Plasma with X11.
      gcc:

       Using built-in specs.
       COLLECT_GCC=gcc
       COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/lto-wrapper
       Target: x86_64-pc-linux-gnu
       Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-pkgversion='Arch Linux 9.3.0-1' --with-bugurl=[https://bugs.archlinux.org/] --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
       Thread model: posix
       gcc version 9.3.0 (Arch Linux 9.3.0-1)
      

      gdb:

       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.
      

      If you need some more info, I'd be glad to provide it.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            hjk hjk
            gbalog Yury DoesntMatter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes