ssbssa / heob

Detects buffer overruns and memory leaks.
Boost Software License 1.0
156 stars 25 forks source link

Can't use self-built heob in Qt Creator #11

Closed mitchcurtis closed 6 years ago

mitchcurtis commented 6 years ago

I'm trying to run a self-built heob in Qt Creator, but get the following error message:

The Heob executables must be in the appropriate location.

This is the build output from build.bat on a Windows 10 machine:

C:\dev\heob>build.bat

C:\dev\heob>echo C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\ATLMFC\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\lib\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\um\x64; | find /i "lib\amd64" 1>NUL

C:\dev\heob>if errorlevel 1 (set bits=32 ) else (set bits=64 )

C:\dev\heob>if not exist obj32 mkdir obj32

C:\dev\heob>if defined HEOB_VERSION set HEOB_VERSION_RC=/d HEOB_VER_STR=\"\"

C:\dev\heob>if defined HEOB_VER_NUM set HEOB_VER_NUM_RC=/d HEOB_VER_NUM=

C:\dev\heob>if defined HEOB_PRERELEASE set HEOB_PRERELEASE_RC=/d HEOB_PRERELEASE=

C:\dev\heob>if defined HEOB_COPYRIGHT_YEARS set HEOB_COPYRIGHT_YEARS_RC=/d HEOB_COPYRIGHT_YEARS=\"\"

C:\dev\heob>set RCFLAGS=

C:\dev\heob>if not defined DWSTFLAGS set DWSTFLAGS=/D NO_DWARFSTACK

C:\dev\heob>if not defined HEOB_VERSION set HEOB_VERSION=vc-dev

C:\dev\heob>set HEOBVER=/D "HEOB_VER=\"vc-dev\""

C:\dev\heob>set CFLAGS=/GS- /W3 /Gy- /Zc:wchar_t /D NO_DWARFSTACK /Gm- /O2 /Ob0 /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "HEOB_VER=\"vc-dev\"" /D "_MBCS" /errorReport:prompt /GF- /WX /Zc:forScope /GR- /Gd /Oy- /Oi /MD /openmp- /nologo /Fo"obj32\" /Ot /wd4996

C:\dev\heob>set LDFLAGS=/NXCOMPAT /DYNAMICBASE "kernel32.lib" /OPT:REF /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /NODEFAULTLIB /TLBID:1

C:\dev\heob>rc /foobj32\heob-ver.res heob-ver.rc Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384 Copyright (C) Microsoft Corporation. All rights reserved.

C:\dev\heob>if errorlevel 1 goto error

C:\dev\heob>cl /c /GS- /W3 /Gy- /Zc:wchar_t /D NO_DWARFSTACK /Gm- /O2 /Ob0 /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "HEOB_VER=\"vc-dev\"" /D "_MBCS" /errorReport:prompt /GF- /WX /Zc:forScope /GR- /Gd /Oy- /Oi /MD /openmp- /nologo /Fo"obj32\" /Ot /wd4996 heob.c heob.c

C:\dev\heob>if errorlevel 1 goto error

C:\dev\heob>cl /c /GS- /W3 /Gy- /Zc:wchar_t /D NO_DWARFSTACK /Gm- /O2 /Ob0 /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "HEOB_VER=\"vc-dev\"" /D "_MBCS" /errorReport:prompt /GF- /WX /Zc:forScope /GR- /Gd /Oy- /Oi /MD /openmp- /nologo /Fo"obj32\" /Ot /wd4996 heob-inj.c heob-inj.c

C:\dev\heob>if errorlevel 1 goto error

C:\dev\heob>link /OUT:"heob32.exe" /NXCOMPAT /DYNAMICBASE "kernel32.lib" /OPT:REF /INCREMENTAL:NO /SUBSYSTEM:CONSOLE /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /NODEFAULTLIB /TLBID:1 /IMPLIB:obj32\heob.lib obj32\heob.obj obj32\heob-inj.obj obj32\heob-ver.res Creating library obj32\heob.lib and object obj32\heob.exp

C:\dev\heob>if errorlevel 1 goto error

C:\dev\heob>goto eof

C:\dev\heob>

I get the following build artifacts:

C:\dev\heob>tree /F
Folder PATH listing for volume Windows
Volume serial number is C056-E24F
C:.
│   .gitignore
│   .gitmodules
│   allocer.cpp
│   build.bat
│   crt32-vc6.def
│   crt32.def
│   crt64.def
│   dll-alloc.cpp
│   heob-inj.c
│   heob-internal.h
│   heob-ver.rc
│   heob.c
│   heob.h
│   heob.ico
│   heob.manifest
│   heob.qbs
│   heob.qbs.user
│   heob32.exe
│   LICENSE_1_0.txt
│   logo-16.png
│   Makefile
│   README.md
│   vc.bat
│
├───dwarfstack
├───obj32
│       heob-inj.obj
│       heob-ver.res
│       heob.exp
│       heob.lib
│       heob.obj
│
├───qt-creator
│       .gitignore
│       heob.json.in
│       heob.pro
│       heobconstants.h
│       heobplugin.cpp
│       heobplugin.h
│
└───testres
        test-01.txt
        test-02.txt
        test-03.txt

The problem could be that the x64 binaries aren't built? I'm using the x64 command prompt.

ssbssa commented 6 years ago

The Heob executables must be in the appropriate location.

This means it didn't find the heob executable in the directory you set. If you run heob with a 64bit program, then you need the heob64.exe.

The problem could be that the x64 binaries aren't built? I'm using the x64 command prompt.

Yes, looks like you're right about that. If you used the x64 command prompt, then heob64.exe should have been built, not heob32.exe. Seems the detection of 32/64 bit doesn't work for you, it is very simple:

echo %lib% |find /i "lib\amd64" >NUL
if errorlevel 1 (
  set bits=32
) else (
  set bits=64
)

And in your case %lib% has this: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\ATLMFC\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\lib\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.15063.0\um\x64 There is no lib\amd64, only lib\x64. I've so far only used MSVC 2015, and in 2017 this seems to have changed.

So maybe just change it to echo %lib% |find /i "lib\x64" >NUL and try again.

mitchcurtis commented 6 years ago

Thanks, changing it to that fixes it.

What's weird is that even using the self-built one, I don't get the option to debug the heob when it crashes. Is it not using debug information?

ssbssa commented 6 years ago

No, it's not. I don't need to debug heob often lately, and if I do, I usually use gcc/gdb.

ssbssa commented 6 years ago

You get debug information with build.bat if you add /Zi to CFLAGS, and /DEBUG to LDFLAGS.

ssbssa commented 6 years ago

Oops, I didn't mean to close this one, pushed the wrong button.

ssbssa commented 6 years ago

Since you were able to use your self-built heob, and no new questions came up, I'm closing this now.