Click here to Skip to main content
11,571,102 members (64,001 online)
Click here to Skip to main content
Add your own
alternative version

Post mortem C++ exception analysis in embedded applications

, 21 Aug 2009 CPOL 26.3K 198 27
An article on analysing a program exception or software crash.
CallStackTest_src.zip
CallStackTest
CallStackTest
Ensor6 (x86)
Debug
Win32
Debug
Release
DiaTool
DiaTool
DiaTool.csproj.user
Properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// C:\Program Files\Microsoft Visual Studio 9.0\DIA SDK\bin\msdia90.dll -> Library Dia2 2.0
// http://msdn.microsoft.com/en-us/library/x93ctkx8(VS.80).aspx

namespace DiaTool
{
    class Program
    {
        static void Main(string[] args)
        {
            string output = System.IO.Directory.GetCurrentDirectory() + "\\Output.txt";
            bool help = false;
            bool process = false;
            List<string> pdbFiles = new List<string>();
            List<string> filesToAnalyze = new List<string>();

            for (int i = 0; i < args.Length; ++i)
            {
                string arg = args[i].ToLower();

                if (arg.StartsWith("/p:"))
                {
                    string filename = arg.Substring(3);
                    if (System.IO.File.Exists(filename))
                    {
                        using (System.IO.StreamReader reader = new System.IO.StreamReader(filename))
                        {
                            while (!reader.EndOfStream)
                            {
                                string file = reader.ReadLine().ToLower();
                                if (file.StartsWith(";"))
                                {
                                    continue;    // comment
                                }
                                if (file.EndsWith(".pdb") && System.IO.File.Exists(file))
                                {
                                    if (pdbFiles.Contains(arg) == false)
                                    {
                                        pdbFiles.Add(file);
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Could not open file : '{0}'", file);
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Could not open input file : '{0}'", filename);
                        return;
                    }
                }
                else if (arg.StartsWith("/a:"))
                {
                    string filename = arg.Substring(3);
                    if (System.IO.File.Exists(filename))
                    {
                        if (filesToAnalyze.Contains(arg) == false)
                        {
                            filesToAnalyze.Add(filename);
                        }
                    }
                }
                else if (arg.StartsWith("/o:"))
                {
                    output = arg.Substring(3);
                }
                else if (arg.StartsWith("/s"))
                {
                    process = true;
                }
                else if ((arg == "/h") || (arg == "/?"))
                {
                    help = true;
                }
                else // can only be pdb file
                {
                    if (arg.EndsWith(".pdb") && System.IO.File.Exists(arg))
                    {
                        if (pdbFiles.Contains(arg) == false)
                        {
                            pdbFiles.Add(arg.ToLower());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Wrong input parameter : '{0}'", args[i]);
                        return;
                    }
                }
            }

            if (help == true)
            {
                Console.WriteLine("DiaTool.exe [/i:<input file> | <pdb file1> .. <pdb file n>] [/o:<output file>] [/h | /?]");
                Console.WriteLine("  /p:<input file>  : file that contains list of pdb files to parse");
                Console.WriteLine("  /a:<input file>  : file to analyze");
                Console.WriteLine("  /o:<output file> : name of file to write all debug symbol function names to if option '/p' is set. If omitted, default is 'Output.txt'");
                Console.WriteLine("  /h | /?          : print help");
                Console.WriteLine();
                return;
            }

            Dia dia = new Dia(pdbFiles, filesToAnalyze, output);
            if (process == true)
            {
                dia.Process();
            }
            dia.Analyze();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Werner Willemsens
Team Leader
Belgium Belgium
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 21 Aug 2009
Article Copyright 2009 by Werner Willemsens
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid