debugging the DLL

Arkatakor

King
Joined
Mar 11, 2006
Messages
620
Location
Stockholm, Sweden
After successfully compiling the DLL for a mod, I have been trying to debug the dll in visual C++ 2010 express.

I imported an existing project; when I press F5 to debug the mod, I get a window popup with the text:

Unable to start program '<PATH_TO_SOLUTION_DIRECTORY>\CvGameCoreDLL.dll'

It is somehow expecting that the DLL should be in the same directory as the solution and source files themselves. The only place that the DLL should be in is the debug folders of the solution (when its compiled), then it should be copied ASSETS directory of the mod. I get as far as this.

So what I would like to do is to tell the visual C++ 2010 express that I would like to debug the DLL in the ASSETS directory of the mod which is in a completely different directory than that of my source files / solution.

TLDR; I would like to instruct the compiler that the DLL its trying to debug is in another directory than that of my source / solutions files. How do I do that?
 
After successfully compiling the DLL for a mod, I have been trying to debug the dll in visual C++ 2010 express.

I imported an existing project; when I press F5 to debug the mod, I get a window popup with the text:

Unable to start program '<PATH_TO_SOLUTION_DIRECTORY>\CvGameCoreDLL.dll'

It is somehow expecting that the DLL should be in the same directory as the solution and source files themselves. The only place that the DLL should be in is the debug folders of the solution (when its compiled), then it should be copied ASSETS directory of the mod. I get as far as this.

So what I would like to do is to tell the visual C++ 2010 express that I would like to debug the DLL in the ASSETS directory of the mod which is in a completely different directory than that of my source files / solution.

TLDR; I would like to instruct the compiler that the DLL its trying to debug is in another directory than that of my source / solutions files. How do I do that?

F5 will try to compile and start your program. Since you didn't work with a program, but a library (dll), you cannot start it.

To debug, start civ (with your debug DLL), then click "Attach to process" (or similar, don't have an english version).

AFAIK in 2010, "Attach to process" is hidden by default, so if you didn't find it in the toolbar or menus, you have to right-click on the toolbar, select the last option in the menu (something like "customize"), select the second tab (Commands?). Then add the "Attach process" command in the "debug" group wherever you like it to have.
 
F5 will try to compile and start your program. Since you didn't work with a program, but a library (dll), you cannot start it.

To debug, start civ (with your debug DLL), then click "Attach to process" (or similar, don't have an english version).

AFAIK in 2010, "Attach to process" is hidden by default, so if you didn't find it in the toolbar or menus, you have to right-click on the toolbar, select the last option in the menu (something like "customize"), select the second tab (Commands?). Then add the "Attach process" command in the "debug" group wherever you like it to have.
Ok I will try this. I am using the following make file in my project in which the executable of civ4 is already specified:

Spoiler :
#### Paths ####
TOOLKIT=C:\Program Files (x86)\Microsoft Visual C++ Toolkit 2003
PSDK=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A
CIVINSTALL=D:\games\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword
GLOBALBOOST=$(CIVINSTALL)\CvGameCoreDLL\Boost-1.32.0
GLOBALPYTHON=$(CIVINSTALL)\CvGameCoreDLL\Python24
TORTOISE="C:\Program Files\TortoiseSVN"
## Uncomment to have newly compiled dlls copied to your mod's Assets directory
##YOURMOD=D:\games\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Mods\romDev\Rise of Mankind - A New Dawn
YOURMOD=D:\games\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Mods\romDev\Rise of Mankind - A New Dawn

mod=\romDev\Rise of Mankind - A New Dawn

#### Tools ####
CC="$(TOOLKIT)\bin\cl.exe"
CPP="$(TOOLKIT)\bin\cl.exe"
LD="$(TOOLKIT)\bin\link.exe"
RC="$(PSDK)\bin\rc.exe"
WCREV="$(TORTOISE)\bin\SubWCRev.exe"
## Uncomment to build dependencies using fastdep
FD="$(MAKEDIR)\bin\fastdep.exe"

#### BLACKLIST ####
## Uncomment to block CvTextScreen (accidentally included by Firaxis)
BLACKLIST=CvTextScreens

#### You shouldn't need to modify anything beyond this point ####
#################################################################

Debug_GLOBAL_CFLAGS= /D_MOD_SENTRY /D_MOD_FRACTRADE /D_MOD_GOVWORKERS /DQC_MASTERY_VICTORY /DLOG_AI /D_MOD_GWARM /D_MOD_SHAM_SPOILER /DFP_PROFILE_ENABLE /DC2C_BUILD /DUSE_INTERNAL_PROFILER
Final_Release_GLOBAL_CFLAGS= /D_MOD_SENTRY /D_MOD_FRACTRADE /D_MOD_GOVWORKERS /DQC_MASTERY_VICTORY /D_MOD_GWARM /D_MOD_SHAM_SPOILER /DC2C_BUILD
Release_GLOBAL_CFLAGS= /D_MOD_SENTRY /D_MOD_FRACTRADE /D_MOD_GOVWORKERS /DQC_MASTERY_VICTORY /DLOG_AI /DFP_PROFILE_ENABLE /D_MOD_GWARM /D_MOD_SHAM_SPOILER /DC2C_BUILD /DUSE_INTERNAL_PROFILER

#### Target Files ####
Debug_BIN=Debug\CvGameCoreDLL.dll
Release_BIN=Release\CvGameCoreDLL.dll
Final_Release_BIN=Final_Release\CvGameCoreDLL.dll

!IF [IF NOT EXIST CvGameCoreDLL.rc EXIT 1] == 0
Debug_RESOURCE=Debug\CvGameCoreDLL.res
Release_RESOURCE=Release\CvGameCoreDLL.res
Final_Release_RESOURCE=Final_Release\CvGameCoreDLL.res
!ENDIF

Debug_STATICLIB=Debug\CvGameCoreDLL.lib
Release_STATICLIB=Release\CvGameCoreDLL.lib
Final_Release_STATICLIB=Final_Release\CvGameCoreDLL.lib

Debug_LIBDEF=Debug\CvGameCoreDLL.def
Release_LIBDEF=Release\CvGameCoreDLL.def
Final_Release_LIBDEF=Final_Release\CvGameCoreDLL.def

Debug_PCH=Debug\CvGameCoreDLL.pch
Release_PCH=Release\CvGameCoreDLL.pch
Final_Release_PCH=Final_Release\CvGameCoreDLL.pch

Debug_PDB=Debug\CvGameCoreDLL.pdb
Release_PDB=Release\CvGameCoreDLL.pdb
Final_Release_PDB=Final_Release\CvGameCoreDLL.pdb

Debug_OTHER=Debug\CvGameCoreDLL.exp Debug\CvGameCoreDLL.ilk
Release_OTHER=Release\CvGameCoreDLL.exp
Final_Release_OTHER=Final_Release\CvGameCoreDLL.exp

#### CFLAGS ####
GLOBAL_CFLAGS=/GR /Gy /W3 /EHsc /Gd /Gm- /DWIN32 /D_WINDOWS /D_USRDLL /DCVGAMECOREDLL_EXPORTS /Yu"CvGameCoreDLL.h"
Debug_CFLAGS=/MD /Zi /Od /D_DEBUG /RTC1 /Fp"$(Debug_PCH)" $(GLOBAL_CFLAGS) $(Debug_GLOBAL_CFLAGS)
Release_CFLAGS=/MD /Zi /O2 /Oy /Oi /G7 /DNDEBUG /Fp"$(Release_PCH)" $(GLOBAL_CFLAGS) $(Release_GLOBAL_CFLAGS)
Final_Release_CFLAGS=/MD /Zi /O2 /Oy /Oi /G7 /DNDEBUG /DFINAL_RELEASE /Fp"$(Final_Release_PCH)" $(GLOBAL_CFLAGS) $(Final_Release_GLOBAL_CFLAGS)

#### LDFLAGS ####
GLOBAL_LDFLAGS=/DLL /NOLOGO /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /TLBID:1
Debug_LDFLAGS=/INCREMENTAL /DEBUG /PDB:"$(Debug_PDB)" /IMPLIB:"$(Debug_STATICLIB)" $(GLOBAL_LDFLAGS)
Release_LDFLAGS=/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF /IMPLIB:"$(Release_STATICLIB)" /PDB:"$(Release_PDB)" $(GLOBAL_LDFLAGS)
Final_Release_LDFLAGS=/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF /IMPLIB:"$(Final_Release_LIBDEF)" /PDB:"$(Final_Release_PDB)" $(GLOBAL_LDFLAGS)

#### INCLUDES ####
GLOBAL_INCS=/I"$(TOOLKIT)/include" /I"$(PSDK)/Include" /I"$(PSDK)/Include/mfc" /I"$(GLOBALBOOST)/include" /I"$(GLOBALPYTHON)/include"
PROJECT_INCS=/IBoost-1.32.0/include /IPython24/include
Debug_INCS=$(PROJECT_INCS) $(GLOBAL_INCS)
Release_INCS=$(PROJECT_INCS) $(GLOBAL_INCS)
Final_Release_INCS=$(PROJECT_INCS) $(GLOBAL_INCS)

#### LIBS ####
GLOBAL_LIBS=/LIBPATH:"$(TOOLKIT)/lib" /LIBPATH:"$(PSDK)/Lib" winmm.lib user32.lib psapi.lib
PROJECT_LIBS=/LIBPATH:"$(GLOBALPYTHON)/libs" /LIBPATH:"$(GLOBALBOOST)/libs/" boost_python-vc71-mt-1_32.lib thread.obj exceptions.obj condition.obj xtime.obj mutex.obj once.obj recursive_mutex.obj read_write_mutex.obj tss_hooks.obj
Debug_LIBS=$(PROJECT_LIBS) $(GLOBAL_LIBS) msvcprt.lib #/NODEFAULTLIB:msvcprtd.lib
Release_LIBS=$(PROJECT_LIBS) $(GLOBAL_LIBS)
Final_Release_LIBS=$(PROJECT_LIBS) $(GLOBAL_LIBS)

#### Objects ####
Debug_LINKOBJS=$(Debug_OBJS)
Release_LINKOBJS=$(Release_OBJS)
Final_Release_LINKOBJS=$(Final_Release_OBJS)

#### Auto SOURCES/OBJS ####
!IF [ECHO SOURCES= \> sources.mk] == 0 && \
[FOR %i IN (*.cpp) DO @ECHO. "%i" \>> sources.mk] == 0 && \
[ECHO.>> sources.mk] == 0 && \
[ECHO Debug_OBJS= \>> sources.mk] == 0 && \
[FOR /F "delims=." %i IN ('dir /b *.cpp') DO @ECHO. Debug\%i.obj \>> sources.mk] == 0 && \
[ECHO.>> sources.mk] == 0 && \
[ECHO Release_OBJS= \>> sources.mk] == 0 && \
[FOR /F "delims=." %i IN ('dir /b *.cpp') DO @ECHO. Release\%i.obj \>> sources.mk] == 0 && \
[ECHO.>> sources.mk] == 0 && \
[ECHO Final_Release_OBJS= \>> sources.mk] == 0 && \
[FOR /F "delims=." %i IN ('dir /b *.cpp') DO @ECHO. Final_Release\%i.obj \>> sources.mk] == 0 && \
[ECHO.>> sources.mk] == 0
!INCLUDE sources.mk
!IF [DEL sources.mk]
!ENDIF
!ENDIF

#### Targets ####
#################

.PHONY: all clean Debug_clean Release_clean Final_Release_clean Debug Release Final_Release

all: Debug Final_Release Release

clean: Debug_clean Release_clean Final_Release_clean

Debug_clean:
@FOR %i IN ($(Debug_BIN) $(Debug_STATICLIB) $(Debug_LIBDEF) \
Debug\*.obj Debug\*.@ $(Debug_RESOURCE) \
$(Debug_PCH) $(Debug_PDB) $(Debug_OTHER)) DO @IF EXIST "%i" DEL "%i"

Release_clean:
@FOR %i IN ($(Release_BIN) $(Release_STATICLIB) $(Release_LIBDEF) \
Release\*.obj Release\*.@ $(Release_RESOURCE) \
$(Release_PCH) $(Release_PDB) $(Release_OTHER)) DO @IF EXIST "%i" DEL "%i"

Final_Release_clean:
@FOR %i IN ($(Final_Release_BIN) $(Final_Release_STATICLIB) $(Final_Release_LIBDEF) \
Final_Release\*.obj Final_Release\*.@ $(Final_Release_RESOURCE) \
$(Final_Release_PCH) $(Final_Release_PDB) $(Final_Release_OTHER)) DO @IF EXIST "%i" DEL "%i"

Debug: Debug_DIR Debug_unfinished $(Debug_PCH) $(Debug_BIN)
!IFDEF YOURMOD
-COPY "$(Debug_BIN)" "$(YOURMOD)\Assets\."
!ENDIF

Release: Release_DIR Release_unfinished $(Release_PCH) $(Release_BIN)
!IFDEF YOURMOD
-COPY "$(Release_BIN)" "$(YOURMOD)\Assets\."
!ENDIF

Final_Release: Final_Release_DIR Final_Release_unfinished $(Final_Release_PCH) $(Final_Release_BIN)
!IFDEF YOURMOD
-COPY "$(Final_Release_BIN)" "$(YOURMOD)\Assets\."
!ENDIF

Debug_DIR:
-@IF NOT EXIST "Debug\." MKDIR "Debug"

Release_DIR:
-@IF NOT EXIST "Release\." MKDIR "Release"

Final_Release_DIR:
-@IF NOT EXIST "Final_Release\." MKDIR "Final_Release"

Debug_unfinished:
@ECHO.>Debug\unfinished.@
@FOR /F "delims=@" %i IN ('dir /b Debug\*.@') DO \
@IF EXIST "Debug\%i" DEL "Debug\%i"
@FOR /F %i IN ('dir /b Debug\*.@') DO \
@IF EXIST "Debug\%i" DEL "Debug\%i"

Release_unfinished:
@ECHO.>Release\unfinished.@
@FOR /F "delims=@" %i IN ('dir /b Release\*.@') DO \
@IF EXIST "Release\%i" DEL "Release\%i"
@FOR /F %i IN ('dir /b Release\*.@') DO \
@IF EXIST "Release\%i" DEL "Release\%i"

Final_Release_unfinished:
@ECHO.>Final_Release\unfinished.@
@FOR /F "delims=@" %i IN ('dir /b Final_Release\*.@') DO \
@IF EXIST "Final_Release\%i" DEL "Final_Release\%i"
@FOR /F %i IN ('dir /b Final_Release\*.@') DO \
@IF EXIST "Final_Release\%i" DEL "Final_Release\%i"

$(Debug_BIN): $(Debug_LINKOBJS) $(Debug_RESOURCE)
$(LD) /out:$(Debug_BIN) $(Debug_LDFLAGS) $(Debug_LIBS) $(Debug_LINKOBJS) $(Debug_RESOURCE)

$(Release_BIN): $(Release_LINKOBJS) $(Release_RESOURCE)
$(LD) /out:$(Release_BIN) $(Release_LDFLAGS) $(Release_LIBS) $(Release_LINKOBJS) $(Release_RESOURCE)

$(Final_Release_BIN): $(Final_Release_LINKOBJS) $(Final_Release_RESOURCE)
$(LD) /out:$(Final_Release_BIN) $(Final_Release_LDFLAGS) $(Final_Release_LIBS) $(Final_Release_LINKOBJS) $(Final_Release_RESOURCE)

.cpp{Debug}.obj:
@ECHO.>"$*.obj.@"
$(CPP) /nologo $(Debug_CFLAGS) $(Debug_INCS) /Fo$*.obj /c $<
@DEL "$*.obj.@"

.cpp{Release}.obj:
@ECHO.>"$*.obj.@"
$(CPP) /nologo $(Release_CFLAGS) $(Release_INCS) /Fo$*.obj /c $<
@DEL "$*.obj.@"

.cpp{Final_Release}.obj:
@ECHO.>"$*.obj.@"
$(CPP) /nologo $(Final_Release_CFLAGS) $(Final_Release_INCS) /Fo$*.obj /c $<
@DEL "$*.obj.@"

$(Debug_PCH) Debug\_precompile.obj:
@ECHO.>"$(Debug_PCH).@"
@ECHO.>"Debug\_precompile.obj.@"
$(CPP) /nologo $(Debug_CFLAGS) $(Debug_INCS) /YcCvGameCoreDLL.h /Fo"Debug\_precompile.obj" /c _precompile.cpp
@DEL "$(Debug_PCH).@"
@DEL "Debug\_precompile.obj.@"

$(Release_PCH) Release\_precompile.obj:
@ECHO.>"$(Release_PCH).@"
@ECHO.>"Release\_precompile.obj.@"
$(CPP) /nologo $(Release_CFLAGS) $(Release_INCS) /YcCvGameCoreDLL.h /Fo"Release\_precompile.obj" /c _precompile.cpp
@DEL "$(Release_PCH).@"
@DEL "Release\_precompile.obj.@"

$(Final_Release_PCH) Final_Release\_precompile.obj:
@ECHO.>"$(Final_Release_PCH).@"
@ECHO.>"Final_Release\_precompile.obj.@"
$(CPP) /nologo $(Final_Release_CFLAGS) $(Final_Release_INCS) /YcCvGameCoreDLL.h /Fo"Final_Release\_precompile.obj" /c _precompile.cpp
@DEL "$(Final_Release_PCH).@"
@DEL "Final_Release\_precompile.obj.@"

.rc{Debug}.res:
@ECHO.>"$*.res.@"
$(RC) /Fo$@ $(Debug_INCS) $<
@DEL "$*.res.@"

.rc{Release}.res:
@ECHO.>"$*.res.@"
$(RC) /Fo$@ $(Release_INCS) $<
@DEL "$*.res.@"

.rc{Final_Release}.res:
@ECHO.>"$*.res.@"
$(RC) /Fo$@ $(Final_Release_INCS) $<
@DEL "$*.res.@"

!IFDEF BLACKLIST

Debug\$(BLACKLIST).obj: $(BLACKLIST).cpp
@ECHO.>"$*.obj.@"
@ECHO.>"$*-dummy.cpp"
$(CPP) /nologo $(Debug_CFLAGS) $(Debug_INCS) /Y- /Fo$@ /c "$*-dummy.cpp"
@DEL "$*-dummy.cpp"
@DEL "$*.obj.@"

Release\$(BLACKLIST).obj: $(BLACKLIST).cpp
@ECHO.>"$*.obj.@"
@ECHO.>"$*-dummy.cpp"
$(CPP) /nologo $(Release_CFLAGS) $(Release_INCS) /Y- /Fo$@ /c "$*-dummy.cpp"
@DEL "$*-dummy.cpp"
@DEL "$*.obj.@"

Final_Release\$(BLACKLIST).obj: $(BLACKLIST).cpp
@ECHO.>"$*.obj.@"
@ECHO.>"$*-dummy.cpp"
$(CPP) /nologo $(Final_Release_CFLAGS) $(Final_Release_INCS) /Y- /Fo$@ /c "$*-dummy.cpp"
@DEL "$*-dummy.cpp"
@DEL "$*.obj.@"

!ENDIF

!IF [$(WCREV) . version.svn version.h] != 0
!MESSAGE Error running SubWCRev
!ENDIF

!IFDEF FD

!IF [IF NOT EXIST $(FD) EXIT 1] == 0
!IF [$(FD) --objectextension=pch -q -O Debug CvGameCoreDLL.cpp > depends] != 0 || \
[$(FD) --objectextension=obj -q -O Debug $(SOURCES) >> depends] != 0 || \
[$(FD) --objectextension=pch -q -O Release CvGameCoreDLL.cpp >> depends] != 0 || \
[$(FD) --objectextension=obj -q -O Release $(SOURCES) >> depends] != 0 || \
[$(FD) --objectextension=pch -q -O Final_Release CvGameCoreDLL.cpp >> depends] != 0 || \
[$(FD) --objectextension=obj -q -O Final_Release $(SOURCES) >> depends] != 0
!MESSAGE Error running fastdep.
!ENDIF
!ELSE
!IF [ECHO "fastdep.exe" NOT FOUND! && \
ECHO Please edit Makefile to reflect the correct path of fastdep. && \
ECHO. ]
!ENDIF
!ENDIF

!ENDIF

!IF EXIST(depends)
!INCLUDE depends
!ENDIF

The makefile tells the project where the EXE is situated, thus I remain surprised there is no way to simply tell the compiler that the DLL that its trying to debug is in different directory then that of my source files. It should be possible to configure it as such. This way I can F11 my way into the program as I see fit and skip the attach to process bit.

I have achieved this once for this mod but it was a long time back and I simply don't remember how I configured the project.
 
Use the graphical Attach to Process menu. In VS 2008 it is found under the Debug manu and looks like this.

attachment.php


After you start BtS open this up and select the BtS process (with the DLL and PDB in the Assets folder of your mod). This should attach to the process and enable debugging of all code for which you have symbols (in this case just the DLL).
 

Attachments

  • attach.PNG
    attach.PNG
    10.8 KB · Views: 196
Thanks for the input guys; I am able to debug it by doing the attach to process method. However I simply don't remember ever having to do this when I managed to make it work previously; as far as I remember I could press F11 or F5 and I could launch the program directly as such. The key would be to tell the compiler that the DLL is in a separate directory and to debug it remotely from the current project directory.

Either way this "attach to process" method should solve my problem for now.

AFAIK in 2010, "Attach to process" is hidden by default, so if you didn't find it in the toolbar or menus, you have to right-click on the toolbar, select the last option in the menu (something like "customize"), select the second tab (Commands?). Then add the "Attach process" command in the "debug" group wherever you like it to have.
Thanks for specifying this; it was necessary to follow your steps in order to do this :)
 
However I simply don't remember ever having to do this when I managed to make it work previously; as far as I remember I could press F11 or F5 and I could launch the program directly as such.

These instructions (step 4 is the relevant one for you) will work with VC2010 as well.
 
Back
Top Bottom