游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3049|回复: 2

Valve's VC++ Tricks!

[复制链接]

16

主题

76

帖子

105

积分

注册会员

Rank: 2

积分
105
发表于 2003-10-4 21:25:00 | 显示全部楼层 |阅读模式

This file holds tips and tricks that we've collected.



------- Search and Replace with Perl --------

To search and replace strings in multiple files, do this:
       
        perl -p -i.bak -e "/sSEARCH_FOR/REPLACE_WITH" Filename1 Filename2...

You can do it in a batch command like this:

        for %i in (*.cpp) do perl -p -i.bak -e "/sSEARCH_FOR/REPLACE_WITH" %i


Note that SEARCH_FOR and REPLACE_WITH can be Perl regular expressions.

-i specifies a backup filename extension for the files it processes.
-p wraps the Perl program in code that opens the input file and processes each line in it.
-e tells it to run the following line of Perl code.


------- Large Perforce Integrations -------

When doing Perforce integrations with large numbers of files through the Perforce UI,
you can get in a situation where you can't submit because a few files haven't been
resolved yet, but it is a pain to find the files that aren't resolved yet because the
list of files is huge and there's no hotkey to sort by which files are resolved.

The command line:

  p4 resolve -n

will list files that still need to be resolved so you can find them directly.



------- Expand Pointers To Arrays -------

        To show the elements of an array given a pointer in the watch window, just add a
        comma followed by the number of elements to display:
       
                pArray,25



------- Function Evaluation -------

        Call program code from debugger
        Use quickwatch window, not watch window. e.g. DumpInfo (pFoo)
        Great for debug data
        Use OutputDebugString or printf
        Limitations 20 seconds max.
        Terminate on exception.
        Only one thread

        You can do debug output using OutputDebugString (through our DebugOutStraight call).
        You can also use this to write strings into memory locations by calling sprintf( someString, "a b c d" ).


------- Casting In The Debugger -------

        When in the debugger, you can display a symbol even if it's not in the current module
        or if it's a static in another file.

        The base syntax is {functionName, cppFilename, dllFilename}, but you can usually leave out the first
        two elements like this:
               
        {,,foo.dll}(CMyClass*)pObject   or   {,,foo.dll}symbolName

        If that doesn't work, add the filename:
        {,physics_environment.cpp,vphysics.dll}(CSleepObjects*)pObject

        so using an expression like this inside the engine works:

        {,,client.dll}(C_BaseEntity*){*}pEntity
        {,,client.dll}engine

       
        Note: You can use this to watch the values of local variables in functions up the stack.
        If there's a function like Host_Frame that calls a lot of other functions, and you want to
        watch one of its variables while in other functions, you can do:
               
                {Host_Frame,,engine.dll}someVar


------- Display GetLastError's value and message -------

        You can display the value GetLastError() will return by putting "@err" in your watch window.
        You can see the error message associated with that value by putting "@err,hr" in your watch window.
        If you've placed an HRESULT in a variable, adding ",hr" to the variable name in the watch window will
        display the associated text.


------- Formatting data in the watch window -------

        Most of this was lifted from "Debugging Applications for Microsoft .NET and Microsoft Windows"
        by John Robbins.

        To specify the formatting for an expression in the watch window, add a comma, then the format
        specifier. So "someValue,d" would tell it you want to view the variable called someValue
        as a signed decimal integer.

       
        Symbol                        Format Description
        ------          ------------------
       
        d or i                        Signed decimal integer
        u                                Unsigned decimal integer
        o                                Unsigned octal integer
        x or X                        Hexadecimal integer
        f                                Floating point
        e                                Scientific notation
        g                                Floating point OR scientific, whichever is shorter
        c                                Single character
        s                                ANSI string
        su                                Unicode string
        hr                                HRESULT or Win32 error code
        wc                                Windows class flag
        wm                                Windows message number


        You can also put a pointer in the watch window and have it show a memory dump in a specific format.
        For example, "0xabcdef,ma" would show 64 ASCII characters at 0xabcdef.

        Symbol                        Format Description
        ------          ------------------
       
        ma                                64 ASCII characters
        m                                16 bytes in hex format followed by 16 ASCII characters
        mw                                8 words
        md                                4 doublewords
        mq                                4 quadwords
        mu                                2-byte characters (Unicode)
        #                                Expand an array to the specified number of values (pArray,10)

       
        Note: There is a way to add your own custom expansions for types into the debugger by making
        a DLL that converts the type's data into a string. They're called "Expression Evaluator Add-Ins".
        This may only be supported in .NET.
       

------- Avoiding Stepping Into Things -------
       
        It's often useful to avoid stepping into some common code like constructors or overloaded
        operators. autoexp.dat provides this capability. Add a section called "[ExecutionControl]".
        Add keys where the key is the function name and the value is "NoStepInto". You can specify
        an asterisk (*) as a wildcard as the first set of colons for a namespace or class.
       
        autoexp.dat is only read on Visual Studio's start up.

        To ignore the function myfunctionname, and all calls to the class CFoo:
                [ExecutionControl]
                myfunctionname=NoStepInto CFoo::*=NoStepInto
       
        To ignore construction and assignment of MFC CStrings: (Notice the extra = in CString:perator=.)
                [ExecutionControl]
                CString::CString=NoStepInto CString::operator==NoStepInto

        To ignore all ATL calls:
                [ExecutionControl]
                ATL::*=NoStepInto



------- Syntax Highlighting For New File Extensions -------

To get syntax highlighting for new file extensions, open RegEdit and go to
HKEY_CURRENT_USER\Software\Microsoft\Devstudio\6.0\Text Editor\Tabs/Language Settings.
Pick the closest language under there and add your extension to its FileExtensions key.
For example, you would add PHP files to HTML/FileExtensions since they are essentially
HTML files.

23

主题

515

帖子

552

积分

高级会员

Rank: 4

积分
552
发表于 2003-10-5 10:53:00 | 显示全部楼层

Re:Valve's VC++ Tricks!

翻译一下:(

2

主题

20

帖子

28

积分

注册会员

Rank: 2

积分
28
发表于 2003-10-6 01:06:00 | 显示全部楼层

Re:Valve's VC++ Tricks!

不错不错,以后我也可以拿来用了

楼上的,搞程序这点e文还是要会的阿
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-5-20 08:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表