CIDLib Utilities
Welcome To CIDCorp
Home of the CIDLib Class Libraries


Utility Programs

CIDLib comes with a number of small, but useful, utility programs which aid in development and debugging. These utilities are included for your convenience, but I cannot guarantee that they are without flaw. I use them myself without problems, but I have a very controlled and stable development environment. None of them though, even if they were to freak out massively, are of the type which would cause any data loss or destruction.
Dependency Analyzer
CIDDep.Exe is a dependency analyzer which will scan the source files of a project and build a header dependency file appropriate for the DMake make program supported by CIDLib. It is probably quite fine for NMake, but I have not confirmed this. Let me know if it is not and perhaps I can support both formats via a switch. The Mak files that come with the CIDLib system all expect a dependency file in the form xxxx.Depend, where xxxx is the name of the project. So a project named Sinewave will look for Sinewave.Depend. How To Use It You invoke the dependency analyzer by telling it what Cpp files to search. It will search them and dump the output to the indicated output file. You can also provide no output file and it will dump to the standard out, then just redirect the output to the correct file.

So, for the Sinewave.Exe program, it would look like this:

    CIDDep /OUT=Sinewave.Depend *.Cpp          
Limitations and Gotchas In order for CIDDep to work, it must be able to correctly tell the difference between user and system include files. Therefore you must use "" double quotes when including your own or CIDLib include files, saving the <> angle brackets for system include files (which you should not need anyway since CIDLib provides all the need functionality.)

CIDDep also does not understand all of the various ways of doing conditional compilations. It understands these forms:

    #if     defined(XYZ)
    // Include this if XYZ is defined
    #endif

    #if     !defined(XYZ)
    // Don't include this if XYZ is defined
    #endif

    #if     defined(ABX)    \
            || (defined(XYZ)
    //
    //  Include this if ABC or XYZ is included. Note that they are put
    //  on separate lines. Only the || (OR) condition is understood
    //  right now. And also note that the \ line extension character is
    //  required to wrap the conditional test to multiple lines.
    //
    #endif

MapDump.Exe, Map File Parser

The Map File Parser utility will help you when you get traps and want to find out where the trap addresses map to within a Dll (Exe map files generally don't have enough information of this type to be useful.) It is particularly convenient because of the fact that the names in the .Map file are mangled with C++ type information.

The CIDLib system will catch any traps and/or fatal runtime errors and generate a file, in the current directory, with the name ErrorInf.CIDLib. This file will contain the information about the trap/error and a trace up the call stack from the place of the error to the start of that thread. Each entry in the call stack trace indicates which Dll/Exe the call was in, along with an offset within that Dll/Exe. You can use the MapDump.Exe program to map this address to a method. It will look for the closest match in the map file, unmangle it, and display it. The displayed method name has all of the type information of the parameters. How To Use It You invoke this utility by giving it the hex address of the function, from the error dump, and the map file. So, if your output files are going to C:\MyResDir and you got an error at 0x20021in MyDll.Dll, you would type:

    MapDump 0x20021 C:\MyResDir\MyDll.Map          

The output might look something like this:

    MapDump.Exe, A CSet/2++ Map File Parser Utility          
    Copyright (c) `CIDCorp 1994..1995          
    Author: Dean Roddey          

    Closest match is symbol: MyClass::MyFunction(const TMyType* const,double)
Limitations and Gotchas Since only publically available methods are in the Map file, sometimes a trap in an internal method will cause a mapping to the nearest public API. So be careful of this. Usually it is obvious that this has happened by tracing the stack calls. Somewhere along the line you had to have called a public API to get into the Dll to begin with. So, there are usually enough clues to know what has happened.

You will have to keep the Map files of any releases you send into the field in order to be able to map trap/error info provided by the client to places in the code for that release.

MiniMetrics.Exe, Metrics Monitor Utility

MiniMetrics.Exe is a small metrics browser for the CIDLib system. CIDLib supports an object oriented metrics system, both for itself and for client programs. It makes these metrics values available to external metrics programs, such as the MiniMetrics program. MiniMetrics is a very simple browser which is purposefully written in raw PM so as to avoid any dependencies upon the CIDLib code that it is used to debug. Eventually, a second more powerful and flexible metrics program will be created, though MiniMetrics will remain as the ultimate sanity check. How To Use it MiniMetrics has no parameters and is not sensitive to its current directory so just type the program name from whereever you happen to be. Once it is running, use its menu to start a new monitor session. A monitor session will monitor a single `metrics group', which is a set of up to 32 metrics values.

When you start a new session, you will be presented with a dialog which shows the available applications on the left and the available metrics groups on the right. As you select different applications in the left list box, the metrics groups available to you will be updated on the right. Make the appropriate selections and press the Accept button.

The top group of fields display information that is process wide. For instance, each application has an unsigned field and a string to which it can write program specific information. And there is also the termination code left when the program exits and the process' state. Gotchas and Limitations MiniMetrics does not automatically update itself. You must use the refresh buttons provided to cause the displayed value to update from the target program's metrics info. It is also updated when you first select that value in the list box of available metrics in the current group, so you can just put the focus on that list box and arrow up and down. Behind The Scenes Under the covers, MiniMetrics uses the CIDLib system's `Process Registry' system. Every CIDLib program is magically registered with this registry which can be accessed by external programs that understand the registry format. Each program gets an entry in the registry which contains some basic information, but most importantly the name of the program and its process id. With this information, the external application can build the names to a number of shared IPC resources to communicate with the application. This works because CIDLib.Dll (the lowest of the object oriented CIDLib Dlls) builds the names to these magical resources using the process id of the host application.

One of these shared resources is the process' metrics data area. When you choose "New Session" and select a process, that list of processes comes from the process registry. When you select on, MiniMetrics builds the name to associated metrics information using the process id it gets from the registry entry for the selected process.

CIDBuild.Exe, Build Shell

To simply my own development chores, I over time wrote a very complex build environment in Rexx. This served me well for a long time; however, I wanted to develop a more flexible and powerful system which I could also distribute with the system. The Rexx system was just too loose for distribution in my opinion and was beginning to run out of steam for my own development. Therefore I wrote CIDBuild, which is my own custom build shell.

CIDBuild is a raw C++ program. It does not depend upon any CIDLib functionality since it is used to build CIDLib itself. It is just a TTY style program that acts as much as possible like the standard command line prompt. When you type commands, any unrecognized stuff is passed on to Cmd.Exe to be interpreted as usual. CIDBuild specific commands are handled by the shell itself. This allows it to provide value added command line functionality.

CIDBuild uses a text project file, written by you, to describe the build environment, the projects, and the attributes of those projects. It also supports a powerful symbolic token system.

CIDLib comes with a project file for building itself and its demo programs, which is set up so that you can build CIDLib right there in place under the CIDLib installation directory. This is fine for playing around; but, if you want to do serious work or have your own build tree, then you will want to set up your own development tree with its own project file. How To Use It Once you have done the CIDLib installation and setup, you should be able to just run the build environment. It has one parameter which controls the build mode, which should be Dev or Prod (case does not matter.) This environment variable will cause the build shell to define one of two special symbolic values DEVBUILD or PRODBUILD. These are used inside the project file to do conditional compilation, see Symbolic Values below.

    CIDBuild [Dev|Prod]          
It will display some startup information, parse the project file, and present a prompt, ready to go to work. To see a list of the available commands, type ? at the prompt. To see help on a particular command, then type:
    xxx ?

    where xxx is the command of interest.
The Dev or Prod command line parameter will cause either the DEVBUILD or PRODBUILD token to be defined. You can use this to put conditional code into the project file for either development or producton builds. Gotchas and Limitations This is the first release of the build shell so it definitely has limitations. Don't worry though, the next release is hosted on NT and will be based around the VC++ IDE and project system.

The known and obvious limitations are:

  • If you change the project file, you must shutdown the environment and start it back up again, to reparse the file. This is good and bad. Its good because you can edit the project file while the shell is open, but bad because its a pain to stop and start the shell a lot when you are first creating a project file and making mistakes.
  • The SET command prevents the setting of OS/2 environmental variables at this time because it is interpreted as an attempt to set an shell variable. Shell Commands This section describes each shell command, what it does, any potential gotchas or limitations, and the expected outcome. Keep in mind that, in any command you type, symbols in the form $(xxx), where xxx is the symbol name, are expanded before the command is evaluated. To keep symbols from being expanded before the evaluation, use the form $$(xxx). The first $ will be stripped off and the $(xxx) used as is. This is important in the Prompt command, as discussed below. Some commands also provide specalized, more limited ways to indicate symbolic values, but this style is always accepted at any place in the typed command. BldDeps This command will find all projects defined in the project file and invoke the dependency ana- lyzer on them. It changes to the project directory and runs the analyzer on on all of the *.Cpp files, outputing to the project's dependency file (which is always named xxx.Depend, where xxx is the name of the project.) CD The shell provides some added value to the `change directory' command. It recognizes this form:
        CD @xxx
    
    where xxx is either a symbol defined in the project file (or manually from the shell command line) or a project name. First the list of defined projects is searched. If xxx matches a project name, then the current directory is changed to the home directory of that project. Otherwise it is assumed to be a symbolic value and the symbol is expanded and used as a directory name. If no symbolic values are present, then the command is executed verbatim. Note that, unlike the OS/2 command line, there must be a space between CD and the directory. I.e. you can't type CD\MyDir, though that is a valid OS/2 command line. Cmp This command will compile a particular target file or set of target files for the project in the current directory. So it assumes that there is one and only one .Mak file in the current directory.

    Cmp has these forms:

        Cmp filename          
        Cmp DEPEND          
    
    The first form compiles one or more target files, such as *.Obj or MyProject.Res. Note that the case of the target file is significant, and must match that of the actual file on disk (a side effect of DMake.) The second form just rebuilds the dependency file for the project in the current directory.

    Contrast the Cmp command to the Make command which rebuilds the entire project, or at least any files that are out of date from DMake's perspective. Dbg The Dbg command is a wrapper around the debugger invocation. It handles providing the project name and setting up the environment the same as when the project was built. You must be in a project directory to invoke this command because it looks for a Mak file and uses that as the project name.

    Dbg has these forms:

        Dbg [parms]          
        Dbg RAW          
    
    The first version invokes the debugger with the project Exe name and passing along any parameters given to the Dbg command. The second command does the same environmental setup but does not provide the exe name, so the debugger startup dialog shows up.

    If no parameters are provided to the Dbg command, then the symbol $(DefDbgFlags) is used. This symbol defaults to /p- if you don't set it in the project file or via the command line. The /p- tells the debugger not to reuse the profile for this project. If you want to have the default be to use the old profile, then set it to "" or /p+.

    If you set the DBGPARMS attribute for the project file, these will be passed as the parameters to the program being debugged. Otherwise you will not be given a chance to give program parameters. If you set like this, DBGPARMS=*, then you will be prompted for program arguments when you invoke the dbg command. Note that the same command line editing and recall is available here as at the main shell prompt. Dir The Dir command is similar to the CD command in that it works like usual but understands the special parameter @xxx as either a project name or a symbolic value, in that order. However it also allows you to provide a separate wild card.

    Dir has these forms:

        Dir @projname [wildcard]
        Dir @symbol [wildcard]
        Dir [wildcard]
    
    The first form will show all (or the matching) files within the home directory of the indicated project. The second format will show all (or the matching) files within the directory obtained by expanding the indicated symbol. The last form is basically just like the regular OS/2 command line Dir. DlgEd This command will invoke the dialog editor for the resources in the current directory. It will copy the .Res file from the result directory to the current project directory, invoke the dialog editor on that file, then copy it back on save. Doing the work in the current directory gets around some wierdness in the dialog editor's way of dealing with paths. GrepAll This command will do a grep on the directory of every defined project. I did this one as a convenience for myself, but you might find it useful also. It assumes your grep program is named Grep.Exe.

    The form is:

        GrepAll [options] pattern
    
    where pattern is the pattern to grep for. The options, and the format of your pattern string, are determined by the grep utility you use. Home The shell recognizes a special symbol $(Home) that should be set to your home directory. This command is equivalent to typing CD @Home or CD $(Home). The Home symbol, like any other user settable symbol, can be set in the project file and/or via the command line.

    Since it is used so often, you can change the home token by just typing Home xxxxx, where xxxx is the new home directory. You will be changed to that directory and it will become the new home directory. Make The Make command will build an entire project, or at least as much of it as is required to bring it up to date. Basically this command just invokes DMake with the Mak file as the parameter. If your make files are built correctly, such that the first target will cause all required updates, then this command will build the entire project. This sometimes requires a dummy first target, which references multiple top level target files just because of the hierarchical dependency nature of make files. Some projects only have one end result file, but some have two. An example is a Dll project, which needs to generate a Lib file and a Dll file. MakeRel This command is only for my internal use at this time. It builds my releases automatically for me. It may, in some future release, be made flexible enough to do the same for you; but, at this time it has too many assumptions about my particular needs to be of general use. Project The project command shows you information about projects. Each project defines a set of special symbols, and optionally defines some environment variables to be set during the build of that project. This command will show you those settings.

    Project has these forms:

        Project projname          
        Project Projname Env          
    
    The first form shows you the magic (i.e. specially understood by the shell) symbols for the project. The second form shows you any environment variables defined for the project (using the SET= form.) SaveSource This command will zip up the entire development tree (which starts at the directory pointed by the _CIDRoot environment variable set before you started the shell) to the archive directory. The archive directory was defined via the _CIDArchive environmental variable.

    This command will maintain up to 9 previous zips. When you issue the command, it will check the archive directory and rename any existing Zips upwards, deleting the 10th one if it exists. The files are named CIDSourceX.Zip where X is the number 1 through 9. The output of the Zip process is dumped to a file named CIDSourceX.List, with the same number X. This lets you go back later and quickly see what was put into the Zip.

    For the demo project file that comes with CIDLib, this command is not very useful since _CIDRoot points to the installation directory. Later though, when you set up your own development tree, it will be more useful. Scrub The scrub command will delete all of the files that are listed in the symbol, $(ScrubList). ScrubList is generally set in the project file but can be set or modified from the shell command line. It is the form of a list of file names (usually wildcards) separated by semicolons, such as:

        *.Bak;*.Err;Dump.Txt;
    
    This makes the scrub command very flexible, however it cannot be defined differently for different projects. It applies the same to any current directory.

    Scrub has these forms:

        Scrub          
        Scrub All          
        Scrub dirname          
    
    The first form scrubs from the current directory. The second scrubs all project directories plus those paths lists in the symbol $(ScrubPath). ScrubPath is a list of directories, like the OS/2 LIBPATH for instance, that should be scrubbed in addition to project directories. The last form will scrub a single target directory. Of course you cannot scrub a subdirectory, of the current directory, named All because that will be interpreted as the second form. Set This command is used to set the value of shell symbols or to view them. It works just like the OS/2 SET command, but it sets shell symbols not OS/2 environment variables.

    Set has these forms:

        SET Symbol          
        SET Symbol=          
        SET Symbol=Value          
    
    The first form shows the current value, if any, of the symbol. The second form sets the symbol to the value ``. The last form sets the symbol to the passed value. Symbols can be used in the Value part of the equation, including the same symbol as is being set (which is how you concatenate onto an existing symbol value.) Show The show command is a grab bag command that will dump out various types of information.

    Show has these forms:

        Show OS2Env          
        Show ShellEnv          
        Show Make          
        Show Projects          
    
    The OS2Env modifier will show the variables of the OS/2 environment as it was seen by the shell when it started. The ShellEnv modifier shows the values of the specially recognized shell symbols. The Make modifier shows the settings defined in the Make project, which is a special environmental project. The Projects modifier shows the currently defined projects, in alphabetical order. Project File Syntax The project file is pretty simple. It allows you to do the following things:
          Define symbolic values          
          Set up the DMake environment          
          Configure the shell prompt          
          Configure some special directories and paths used by the build          
          Configure the projects and their attributes          
    
    Symbolic Values Symbolic values are defined exactly as in C/C++, via the #define keyword. So, if you had a directory that you used a lot in the project file or at runtime, you could define it like this:
        #define MyWorkDir=C:\MyDirectory\Work
    
    To use a symbolic value after it has been defined, you would use it like this:
        #define SomePath=C:\Path1;C:\Path2;$(MyWorkDir);
    
    This would cause MyWorkDir to be expanded when this line is read from the project file. Since the project file is parsed and compiled in a single pass, you must define all symbolic values before they are used (unless they are 'double dollared' so that their value does not get evaluated.)

    Symbolic values can also be used on the command line. When you press Enter after typing a command, any symbolic values are expanded before the command is interpreted. Some commands, such as CD (change directory), have a special syntax for symbolic values, in order to save typing. To change to the directory defined above, I would type:

        CD @MyWorkDir
    
    This is a lot faster than using the standard $(value) syntax, but it can only used in certain commands where its use is unambiguous. Note that CD first checks the symbolic name to see if it is a project name and changes to that project's directory. If its not a project name, then it is looked up as a symbolic name.

    If you want to define a token such that it survives the expansion phase, so that it can be expanded later when used, then type it like this:

       #define Prompt=[$$(CurDir),$$(BuildMode)]
    
    After this, the value of Prompt is [$(CurDir),$(BuildMode)], so the extra dollar sign told the build shell not to expand it. This particular symbolic value, Prompt, often uses this scheme. It is discussed below. Conditional Code You can use conditional code in a project file, though it is limited compared to the capabilities of a C language preprocessor. You can only check whether a value has been defined, not what its value is or whether its value equals some other value. If you look at the provided project file in the Demos subdirectory, you will see it uses the DevBuild and ProdBuild symbols (which are magically set by the build shell according to how it is started) to set up the compile/link flags correctly for development or production code.

    You must use the old style #ifdef xxx keywords to check for value being defined, as apposed to the newer #if defined(xxx) style. Prompt The special symbol Prompt, is used to control the prompt displayed by the shell. The sample project file for the demo programs sets it to:

        #define Prompt=[$$(CurDir),$$(BuildMode)]
    
    So it shows the current directory and the build mode. Basically the prompt lets you display any symbolic values defined by you in the project file or magically by the shell. Note the special syntax with the double dollars to prevent the symbol from getting expanded when the line is read from the project file.

    You can use the Prompt command at runtime to change the prompt, but it will revert to what is defined in the project file the next time the build shell is run. Other Magic Symbols There are a set of magic symbols that are either defined by the shell magically, or that are recognized as special by the shell but are defined by you in the project file. These are:

    Defined by the shell

          Archive      - The value of the _CIDArchive environment variable
          DevBuild     - Defined to 1 if shell is started with Dev parameter
          ProdBuild    - Defined to 1 if shell is started with Prod Parameter
          Rel          - The value of the _CIDRelease environment variable
          Root         - The value of the _CIDRoot environment variable
    
    Special symbols defined by you in the Project file
          BuildPath    - Path to the Build files, see Build Files below          
          DefDbgFlags  - Used by the Dbg command if no parms are provided          
          Prompt       - The prompt the shell should display          
          ScrubList    - The list of files to use with the Scrub command          
          ScrubPath    - The non-project directories to be scrubbed by Scrub All          
          Src          - The Source directory, $(Root)\Source          
    
    Archive is a special one that you may or may not make use of. It is a directory that I use to archive Zips of my source code to periodically. The SaveSource command will zip the entire tree, starting at _CIDRoot, to the archive directory.
    CIDCorp Home Page

    CIDCorp
    Dean Roddey
    Internet: droddey@ng.netgate.net
    CIS: 72170,1614