Linking compiled DLL back to source files during debug

EmperorFool

Deity
Joined
Mar 2, 2007
Messages
9,637
Location
Mountain View, California
I finally have a debug DLL working and have attached to it from VS 2008. However, whenever it hits an exception or failed assertion, it can only show me disassembled code. Where do I point it to the source files that it should use for the code?

Note that the symbols are in place. I see "call CvPlayer::getVisualOwner()" rather than a memory address.
 
I don't know what's the problem, but refar/glider's makefile works fine, so it could be of use to compare your makefile with theirs to see if there's any difference.
 
If it takes you to the Disassembly, then it means the crash happened outside of the primary DLL (so in one of the other DLLs or in the EXE). Frequently these are graphical crashes. You can attempt to use the step functions to get back to the DLL and see where you are, or look at the stack trace and see if there are any recent DLL functions showing, but typically it is a full crash so you cannot proceed at all, and it is from the exe so it is a base function with no stack available.

For these crashes, the best approach is to set up some breakpoints at key locations near where you suspect the crash to be, and slowly narrow down to the most recent function/line and see if that gives you any insight (so placing a breakpoint on each CvPlayer::doTurn could tell you during which player's turn it breaks for instance)

EDIT: Also note that if the Dissembly is open, it will ALWAYS take you to it instead of to the actual code, so close it when opened, or even set the options to never open it without permission to begin with,
 
I don't know what's the problem, but refar/glider's makefile works fine, so it could be of use to compare your makefile with theirs to see if there's any difference.

The makefile only governs building the DLL; it shouldn't affect how Visual Studio operates. Of course I won't say that it cannot affect it, but since the symbols are showing up I believe that should be all that I need.

If it takes you to the Disassembly, then it means the crash happened outside of the primary DLL.

Except that the stack trace shows that the crash happened in the DLL, and I was able to use the disassembly to find the line where it crashed thanks to the symbols. I didn't try closing the disassembly window and picking a different function, so I'll try that next time.

I thought I recently read one of your very recent posts (1 week?) saying that you had to point VS to the source files, but I couldn't find it.
 
That was talking about WinDbg. Visual Studio should have your project file open and active when you are running the debugger, and have a fresh compile (preferably FROM Visual Studio, but of course using the Makefile).

I believe there was an option to allow the debugger to open the Assembly, but I THOUGHT it only authorized that when they could not just get into the normal code. It could be there is also an option to ALWAYS use the Assembly (as going to the code only brings you to the active line, and using Assembly can tell you where in that line the issue was, typically only required for IF statements that do multiple checks in a single line though)


If you close the Assembly and hit F10 it should step forward and bring you back to the normal code window, 1 line past the break.
 
Hmm, perhaps I'm not starting it up correctly. Here's what I do:

  1. Compile and install the debug DLL
  2. Launch Civ
  3. See "DLL attached" dialog box
  4. In VS select Attach to Process... and select Civ4BeyondSword.exe
  5. Click OK in #3 dialog box
  6. CRASH!
  7. VS then says that it cannot locate the source for the code and asks if I'd like to see the disassembly. I always leave the "do this automatically" checkbox unchecked.
Is this the correct procedure? I certainly can't launch the DLL from VS AFAIK.
 
I am not familiar with any "DLL attached" dialog box for your number 3.

My Makefile automatically copies the new DLL into my mod directory upon compilation
Code:
Debug-after:
	-@if exist "Debug\CvGameCoreDLL.dll" copy "Debug\CvGameCoreDLL.dll" "C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Mods\Fall Further\Assets"

And VS is set up to launch the process and instantly connect the debugger (though without this setup, you can connect the DLL by using Attach to Process and selecting Civilization BtS as you describe)

To set up VS to launch and link automatically, go to Project->CvGameCoreDLL Properties, selection Configuration Manager->Debugging, in the first line enter C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Civ4BeyondSword.exe (Or whatever your proper directory path is), and in the second line enter mod=\Fall Further with the name of your mod in the place of the name of mine. Basically you just write exactly what is in your shortcut to auto-launch your mod, split into 2 lines.

Once you do this, you can just hit F5 and it will compile your debug DLL, copy it to the mod directory, and launch the mod with the Debugger attached immediately, letting you watch each XML file load and everything else.
 
Back
Top Bottom