private static void HandleTsvStacktrace(string tsvPath, IDiaSession pdbSession)
        {
            var lines = File.ReadAllLines(tsvPath);

            for (int i = 1; i < lines.Length; i++)
            {
                string[] frags      = lines[i].Split('\t');
                string   methodName = "";
                string   module     = "";
                if (frags.Length >= 4)
                {
                    module = frags[1];
                    string rvaStr = frags[3];
                    string rva    = rvaStr.Replace("0x", "");
                    if (frags[2] != "null")
                    {
                        methodName = frags[2];
                    }
                    uint offset = HexToUint(rva);
                    if (pdbSession != null && offset != 0)
                    {
                        string tmpMethodName = DiaHelper.GetMethodName(pdbSession, offset);
                        if (!String.IsNullOrEmpty(tmpMethodName))
                        {
                            methodName = tmpMethodName;
                        }
                    }
                }
                _writer.WriteLine($"at {module}!{methodName}");
            }
        }
        private static void HandleCrashes(dynamic crashes, string pdbFile, string header)
        {
            var pdbSession = DiaHelper.LoadPDB(pdbFile);
            int crashCount = 0;

            _writer.WriteLine();
            _writer.WriteLine();
            _writer.WriteLine();
            _writer.WriteLine();
            _writer.WriteLine();
            _writer.WriteLine(header);
            foreach (var crash in crashes)
            {
                crashCount++;
                string hash = crash.failureHash;
                HandleCrash(hash, pdbSession, crashCount);
            }
        }
 private static void HandleCrash(string hash, IDiaSession pdbSession, int crashCount)
 {
     if (!String.IsNullOrEmpty(hash))
     {
         var crashDetails   = GetCrashDetails(hash);
         int crashOccurence = 0;
         foreach (var crashDetail in crashDetails)
         {
             crashOccurence++;
             string cabId = crashDetail.cabId;
             if (!String.IsNullOrEmpty(cabId))
             {
                 var stackTrace = GetCrashStacktrace(cabId);
                 _writer.WriteLine();
                 _writer.WriteLine();
                 _writer.WriteLine();
                 _writer.WriteLine($"Crash #{crashCount}.{crashOccurence}: {crashDetail.failureName}");
                 _writer.WriteLine();
                 if (stackTrace != null)
                 {
                     foreach (var stackLine in stackTrace)
                     {
                         string methodName = stackLine.function;
                         if (String.IsNullOrEmpty(methodName) || methodName == "null")
                         {
                             string fullOffset = stackLine.offset;
                             string hexOffset  = fullOffset.Replace("0x", "");
                             uint   offset     = HexToUint(hexOffset);
                             if (pdbSession != null && offset != 0)
                             {
                                 methodName = DiaHelper.GetMethodName(pdbSession, offset);
                             }
                         }
                         _writer.WriteLine($"at {stackLine.image}!{methodName}");
                     }
                     if (_preventDuplication)
                     {
                         break;
                     }
                 }
             }
         }
     }
 }
Example #4
0
        private string GetSymbolsFileName(string path)
        {
            try
            {
                return(DiaHelper.GetSymbolsFileName(path));
            }
            catch (Exception ex)
            {
                // If we can't get a pdb, it's unfortunate, but not fatal.  If
                // anything figure out a way to add a warning to the test for the
                // deployment.  Previously we were tracking specific exceptions,
                // and then EqtException and ComException started getting thrown.
                // This was breaking xcopy deployment where DIA is not installed.
                if (EqtTrace.IsWarningEnabled)
                {
                    EqtTrace.Warning("Error while trying to get pdb for assembly '{0}': {1}", path, ex);
                }
            }

            return(null);
        }
        private static void HandleCrashTxtStacktrace(string crashTxt, IDiaSession pdbSession)
        {
            var lines = File.ReadAllLines(crashTxt);

            for (int i = 0; i < lines.Length; i++)
            {
                var currentLine = lines[i];
                if (currentLine.Contains("<BaseAddress>"))
                {
                    string   outputLine = "";
                    string[] splitted   = currentLine.Split(new string[] { "<BaseAddress>" }, StringSplitOptions.None);
                    outputLine += splitted[0];
                    string rva    = splitted[1].Replace("+0x", "");
                    uint   offset = HexToUint(rva);
                    if (pdbSession != null && offset != 0)
                    {
                        string tmpMethodName = DiaHelper.GetMethodName(pdbSession, offset);
                        if (!String.IsNullOrEmpty(tmpMethodName))
                        {
                            outputLine += tmpMethodName;
                        }
                        else
                        {
                            outputLine += "<BaseAddress>" + splitted[1];
                        }
                    }
                    else
                    {
                        outputLine += "<BaseAddress>" + splitted[1];
                    }
                    _writer.WriteLine(outputLine);
                }
                else
                {
                    _writer.WriteLine(currentLine);
                }
            }
        }
        private static void SymbolicateInRightMode(string pdb, string arch, string header)
        {
            string fullPdbPath = Path.GetFullPath(pdb);

            if (!String.IsNullOrEmpty(_tsvPath))
            {
                HandleTsvStacktrace(Path.GetFullPath(_tsvPath), DiaHelper.LoadPDB(fullPdbPath));
            }
            else if (!String.IsNullOrEmpty(_crashTxtPath))
            {
                HandleCrashTxtStacktrace(Path.GetFullPath(_crashTxtPath), DiaHelper.LoadPDB(fullPdbPath));
            }
            else if (!String.IsNullOrEmpty(_failureHash))
            {
                _accessToken = GetClientCredentialAccessToken(_tenantId, _clientId, _clientSecret, DevCenterApiUri).Result;
                HandleCrash(_failureHash, DiaHelper.LoadPDB(fullPdbPath), 1);
            }
            else
            {
                _accessToken = GetClientCredentialAccessToken(_tenantId, _clientId, _clientSecret, DevCenterApiUri).Result;
                var crashes = GetCrashes(arch);
                HandleCrashes(crashes, fullPdbPath, header);
            }
        }