Click here to Skip to main content
15,882,114 members
Articles / Programming Languages / C++
Article

Using the Output Window in DevStudio

Rate me:
Please Sign up or sign in to vote.
4.56/5 (10 votes)
23 Feb 2004CPOL3 min read 58.6K   16   8
How to load arbitrary text into the DevStudio Output Window so you can double-click on a line

Image 1

Contents

Introduction

Ever have a tool like lint, gcc, grep, or the like, whose output references many different places? And then you have to painstakingly check out each of those places by hand? And wouldn't it be nice if you could load the output of that tool into DevStudio and then just double-click on the line and jump straight to that location?

Yeah, me too. But short of writing a full-blown DevStudio Add-In or Macro, which requires some actual work, I didn't know how to do it. Now I do and I'm sharing it for the other equally-clueless out there. And most of us know who we are!

Background

My boss ran lint on some code I had written. This version of lint is extremely picky (good) and resulted in 12,115 lines to check out (bad). Much of it was ignorable but it all had to be checked out. But the time and effort of just going to the indicated lines was looking at about 3 days minimum. 3 looong days.

There had to be a better way. So I looked around at the usual places and was surprised to find no help on how to get an arbitrary file into a DevStudio Output window. I'm sure there is a Microsoft article somewhere, but I couldn't find it. There were several articles on writing Add-Ins and Macros, including the requirements for formatting the filename and line number, but nothing more basic.

It turns out to be very simple. You add a tool to DevStudio, run that tool, and the tool's standard (console) output goes into its own Output Window.

Adding the Tool: Step by Step

From within DevStudio:
  1. Go to the Tools menu, and select Customize...
  2. Select the Tools tab
  3. Scroll to the bottom
  4. Double-click on the empty rectangle
  5. Type name of tool, say "Dump file"
  6. Check "Use output window"
  7. Check "Prompt for arguments"
  8. Set the command to some program that will copy its argument to stdout (I use catfile.bat, shown in all its glory below)
  9. Set the initial directory to $(Wkspdir) or whatever directory turns you on the most

The tool to execute, catfile.bat, is complicated in the extreme. Here's the source:

type %1

Using the Tool

Example -- Lint output

OK, here is an example. Here are a few lines from that dreadful lint output:

    memcpy(&tmpOID[1], &almOID[0], oidLength * sizeof(OIDC_T));
SCTE-Alarms.cpp  599  Info 737: Loss of sign in 
       promotion from int to unsigned
    int
SCTE-Alarms.cpp  599  Warning 534: Ignoring return value of function
    'memcpy(void *, const void *, unsigned int)' (compare with line 44, 
    file string.h)
string.h  44  Info 830: Location cited in prior message
-
    int fullLen = tmpOID[0] + 1; // number of components in tmpOID[]
SCTE-Alarms.cpp  601  Info 713: Loss of precision (initialization) (unsigned
    long to int)
Now before going further, note that the filename and line number sequences are not in a format that DevStudio will recognize. DevStudio wants a sequence like:
filename(linenumber): stuff
So I used a little Perl script to munge the file:
my @file = <>;
chomp @file;
my $line;
foreach $line (@file)
{
    if($line =~ m/^(\S+)\s+(\d+)(.+)/)
    {
        print "$1($2):$3\n";
    }
    else
    {
        print $line, "\n";
    }
}
Now the lines (which I saved in "munged.txt") look like:
    memcpy(&tmpOID[1], &almOID[0], oidLength * sizeof(OIDC_T));
SCTE-Alarms.cpp(599):  Info 737: Loss of sign in 
    promotion from int to unsigned
    int
SCTE-Alarms.cpp(599):  Warning 534: Ignoring return value of function
    'memcpy(void *, const void *, unsigned int)' 
    (compare with line 44, file
    string.h)
string.h(44):  Info 830: Location cited in prior message
_
    int fullLen = tmpOID[0] + 1; // number of components in tmpOID[]
SCTE-Alarms.cpp(601):  Info 713: Loss of precision 
    (initialization) (unsigned
    long to int)
(Obviously, if I was going to be doing this a lot, I would have a dedicated command to do the lint and then the Perl.)

Now, to use the Dump file tool in DevStudio:

  1. Click on the Tools menu
  2. Click on "Dump file" and note that a window pops up asking for the name of the file:

    Picture of one-liner dialog

  3. Enter the name of the file (as shown) and hit OK. Make sure that "Redirect to Output window" is checked. That is the point of this exercise!
  4. The file is loaded into its own Output Window pane. Double-click on a line and see the indicated line show up!

Image 3

Another Example using GCC

OK, let's try another one. I used gcc on a file and got this error output:
sys_conf.h:709: error: `ULONG' was not declared in this scope
sys_conf.h:709: error: syntax error before `)' token

The filename and linenumber are still not quite right, but this Perl script fixes that:

my @file = <>;
chomp @file;
my $line;
foreach $line (@file)
{
    if($line =~ m/^([^:]+):(\d+):(.+)/)
    {
        print "$1($2):$3\n";
    }
    else
    {
        print $line, "\n";
    }
}
yielding munged lines like:
sys_conf.h(709): error: `ULONG' was not declared in this scope
sys_conf.h(709): error: syntax error before `)' token
Now run the Dump file tool and get:

Image 4

Points of Interest

There is nothing particularly magic or clever about this. It is just neat and convenient. But there is a gotcha involved: the output window is limited to 8192 lines. And it is the last 8192 lines from your tool, not the first. Guess how I discovered this with my 12K line lint file...

History

  • 2/24/2004 -- first release
  • 2/25/2004 -- reduced picture sizes to make nice with low-resolution monitors, fixed typo

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Thales Visionix
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNew Method for Gcc with MSVC !!! Pin
send_jk25-Apr-06 16:32
send_jk25-Apr-06 16:32 
GeneralRe: New Method for Gcc with MSVC !!! Pin
jkhax0r21-Nov-07 7:14
jkhax0r21-Nov-07 7:14 
GeneralUsing Output Window for GCC Pin
samboy517-Jul-04 9:18
samboy517-Jul-04 9:18 
GeneralRe: Using Output Window for GCC Pin
Harold Bamford7-Jul-04 9:43
Harold Bamford7-Jul-04 9:43 
GeneralPC Lint Output Pin
gjr9-Mar-04 13:16
gjr9-Mar-04 13:16 
GeneralPC Lint Pin
gjr9-Mar-04 13:15
gjr9-Mar-04 13:15 
GeneralRe: PC Lint Pin
Harold Bamford9-Mar-04 14:16
Harold Bamford9-Mar-04 14:16 
GeneralRe: PC Lint Pin
bmidy2322-Nov-06 23:44
bmidy2322-Nov-06 23:44 
Hi all,

There is also a tool named ALOA, which allow to integrate and analyze lint outpu in VS.
Take a look at it.

Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.