Installing and Debugging the Source Code: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (add link to simplified chinese page)
(rm. a lot of duplicated content)
Line 6: Line 6:
| zh-cn = Installing and Debugging the Source Code:zh-cn}}
| zh-cn = Installing and Debugging the Source Code:zh-cn}}


This article will explain the basic steps for installing and debugging the source code.
== Installing ==


== Step By Step ==
# Run the [[Source SDK]] and choose ''Create a Mod''. See [[Create a Mod]] for details about the process.
# [[Compiler Choices|Choose a compiler]]
# Go! Get started with [[Your First Entity]].


=== Run the Create a Mod wizard ===
To compile your code on Linux, see [[Compiling under Linux]].


# Run the Source SDK from Steam and choose the '''Create a Mod''' link.
== Debugging ==
# You can normally choose any type of mod here, but for the purposes of this tutorial, choose the '''Modify Half-Life 2 Single Player''' option and click '''Next'''.
# In the top edit control of the next dialog, enter a directory where you would like to create a mod. This tutorial will assume you entered '''C:\MyMod'''.
# In the bottom edit control, enter any name for your mod. This will become a subdirectory under your '''''SteamInstallPath'''\SteamApps\SourceMods'' folder. This example will assume you entered '''MyMod''' here.
# Click the '''Next''' button and the source code will be installed on your hard drive.
# Wait for the mod wizard to finish.


=== Compile the Source Code ===
'''Debugging''' is the process of a human examining closely the inner workings of a program. It can reveal the causes of crashes and other bugs.
For general considerations about compilation go here: [[Compiler Choices]]


For more specific:
=== Windows ===
* [[Compiling under VS2003]]
* [[Compiling under VS2005]]
* [[Compiling under VS2008]]
* [[Compiling under VS2010]]


{{note|It is on debug compile by default. In order to run the mod with a debug dll you must right click the mod in the Steam game browser, click '''Properties''' then '''Set Launch Options...''' and add ''-allowdebug'' to the end of anything that may already be there (separated by spaces). You can change to a release build (for distributing the mod) in the configuration manager.}}
# Make sure you are working in the Debug configuration, not Release.
# In the Solution Explorer, right-click on the active project (the one in bold) and choose ''Properties''. It doesn't matter whether you're working with the server or client.
# In the window that appears, choose ''Debugging'' from the left-hand list.
# Change ''Command'' to the path to the .exe file you want to launch (the same on that runs when you play the game/mod in question, e.g. <code>C:\Steam\SteamApps\'''username'''\source sdk base 2007\hl2.exe</code>).
# Change ''Command Arguments'' to read something like <code>-allowdebug -dev -sw -game "C:\Steam\SteamApps\SourceMods\MyMod"</code>
# Change ''Working Directory'' to the folder containing the .exe you chose for Command


Currently the code is better compiling on VS2005. You can download it at http://www.microsoft.com/express/2005/
You can now press F5 at any time to start debugging. (If you really do want to debug in Release mode, repeat the above for that configuration. But don't expect the results to be very useful).


VCE2005 users need to download the [http://www.microsoft.com/downloads/details.aspx?FamilyID=e6e1c3df-a74f-4207-8586-711ebe331cdc&DisplayLang=en Windows SDK] (Windows 2000 users: [http://www.microsoft.com/downloads/details.aspx?familyid=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en Platform SDK]). Visual Studio and VCE2008 users do not.
{{note|You will be told that symbols could not be found for <whatever>.exe - this is normal, as you don't have that source code. Ignore the warning.}}


===Debugging===
==== Run-time attachment ====


==== Setup debugging parameters ====
If you want to debug a process that is already running, choose ''Debug > Attach to Process...'' and select it from the list.


{{note|This will only work if you have installed and launched the Source SDK Base.}}
=== Linux ===
# In the '''Solution Explorer window,''' right-click on the current project (the one in bold) and choose '''Properties'''.
# In the Property Pages dialog that appears, choose the Debugging item on the left-hand side.
# On the right-hand side, in the text control next to '''Command''', enter <code>C:\Steam\SteamApps\'''Username'''\source sdk base 2007\hl2.exe</code> (adjusting the folder names given here to reflect your own Steam installation).
# Next to '''Command Arguments''', enter <code>-dev -sw -game "C:\Steam\SteamApps\SourceMods\MyMod"</code> (where '''MyMod''' is the name of your mod you entered in the ''Create a Mod'' dialog).
# Next to '''Working Directory''', enter <code>C:\Steam\SteamApps\'''Username'''\source sdk base 2007</code> (adjusting the folder names given here to reflect your own Steam installation).
# Click the '''OK''' button.


{{note|If your paths for the options above have spaces, its a good idea to surround them with quotes. For example,  <code>"C:\Steam\SteamApps\'''Username'''\team fortress 2\hl2.exe"</code> etc. It MIGHT work without them, but if you are having trouble with debugging, this is something else to try.}}
# Disable OPTFLAGS in the root makefile
{{note|If you are running the Half-Life 2: Episode One engine, then you can use <code> source sdk base</code> instead of <code> source sdk base 2007</code>}}
# Uncomment DEBUG in your project's makefile. {{confirm|Change it to read <code>-O0 -g -ggdb3</code>.}}
# Make and Install
# Open a terminal window and cd to the location of the executable you are running
<!-- not needed, and bad? # Perform <code>export LD_LIBRARY_PATH=".:bin:$LD_LIBRARY_PATH"</code> -->
# Perform <code>gdb srcds_linux</code> (or whatever the name is)
# Perform <code>run <parameters></code> to start the program


==== Run in the debugger ====
* On a crash ("segfault"), do <code>bt</code> ("backtrace") to see the callstack.
* To break into the debugger, press {{key|Ctrl+C}}; to continue afterwards perform <code>cont</code>.
* To set a breakpoint, do <code>break <function></code>. See <code>help breakpoint</code> for more details.
* To print an expression, do <code>print <expr></code>.


# ''Important: after an SDK update, you must make sure to run whatever game you're editing'' '''through Steam''' ''once (only one time is necessary) before running in the debugger. If you don't, you may get Steam errors when running through the debugger.''
# Right-click on the same project you were editing the properties for, and choose Debug->Start New Instance.
# If you get a warning that <code>hl2.exe</code> has no debugging information, ignore it.
# It should now launch Half-Life 2 and run your code. You can make modifications to the code now, rebuild, and rerun the game with your changes!
==== Alternative: run-time attachment ====
# Start the mod using Steam
# Inside Visual Studio, Main Menu > Debug > Attach to Process...
# Select the hl2.exe process with the title of your mod
{{tip|you can start the app in windowed mode for better comfort : add a "-window" option in your run_mod.bat}}
== Links ==
A good next step after mastering this document is to look at the [[Your First Entity]] document, in which you will make changes to some of the source code.
If you plan to integrate code updates from Valve, and if you want code backups and revision history, take a look at the [[Using Source Control with the Source SDK]] document.


[[Category:Programming]]
[[Category:Programming]]
[[Category:Modding]]
[[Category:Modding]]

Revision as of 10:39, 19 September 2010

Template:Otherlang2

Installing

  1. Run the Source SDK and choose Create a Mod. See Create a Mod for details about the process.
  2. Choose a compiler
  3. Go! Get started with Your First Entity.

To compile your code on Linux, see Compiling under Linux.

Debugging

Debugging is the process of a human examining closely the inner workings of a program. It can reveal the causes of crashes and other bugs.

Windows

  1. Make sure you are working in the Debug configuration, not Release.
  2. In the Solution Explorer, right-click on the active project (the one in bold) and choose Properties. It doesn't matter whether you're working with the server or client.
  3. In the window that appears, choose Debugging from the left-hand list.
  4. Change Command to the path to the .exe file you want to launch (the same on that runs when you play the game/mod in question, e.g. C:\Steam\SteamApps\username\source sdk base 2007\hl2.exe).
  5. Change Command Arguments to read something like -allowdebug -dev -sw -game "C:\Steam\SteamApps\SourceMods\MyMod"
  6. Change Working Directory to the folder containing the .exe you chose for Command

You can now press F5 at any time to start debugging. (If you really do want to debug in Release mode, repeat the above for that configuration. But don't expect the results to be very useful).

Note.pngNote:You will be told that symbols could not be found for <whatever>.exe - this is normal, as you don't have that source code. Ignore the warning.

Run-time attachment

If you want to debug a process that is already running, choose Debug > Attach to Process... and select it from the list.

Linux

  1. Disable OPTFLAGS in the root makefile
  2. Uncomment DEBUG in your project's makefile.
    Confirm:Change it to read -O0 -g -ggdb3.
  3. Make and Install
  4. Open a terminal window and cd to the location of the executable you are running
  5. Perform gdb srcds_linux (or whatever the name is)
  6. Perform run <parameters> to start the program
  • On a crash ("segfault"), do bt ("backtrace") to see the callstack.
  • To break into the debugger, press Ctrl+C; to continue afterwards perform cont.
  • To set a breakpoint, do break <function>. See help breakpoint for more details.
  • To print an expression, do print <expr>.