コード例 #1
0
        public CallStackItem GetSymbolNameFromAddress(UInt32 address)
        {
            CallStackItem result = new CallStackItem();

            if (AddressIsInRange(address))
            {
                IDiaSymbol diaSymbol;
                session.findSymbolByVA(address, SymTagEnum.SymTagFunction, out diaSymbol);

                result.Description = diaSymbol.name + "()";

                IDiaEnumLineNumbers lineNumbers;
                session.findLinesByVA(address, 4, out lineNumbers);

                IDiaLineNumber lineNum;
                uint           celt;
                lineNumbers.Next(1, out lineNum, out celt);

                if (celt == 1)
                {
                    string baseFilename = lineNum.sourceFile.fileName.Substring(lineNum.sourceFile.fileName.LastIndexOf('\\') + 1);
                    result.Source = baseFilename;
                    result.Line   = (int)lineNum.lineNumber;
                }
            }
            else
            {
                result.Description = "<address out of range>";
            }
            return(result);
        }
コード例 #2
0
        protected override List <CallStackItem> GetSymbolNamesFromAddressesInternal(List <UInt32> addresses)
        {
            List <CallStackItem> items = new List <CallStackItem>();

            foreach (UInt32 address in addresses)
            {
                bool found = false;
                foreach (XboxSymbolResolver symbolResolver in symbolResolvers)
                {
                    if (symbolResolver.AddressIsInRange(address))
                    {
                        found = true;
                        items.Add(symbolResolver.GetSymbolNameFromAddress(address));
                    }
                }
                if (!found)
                {
                    CallStackItem result = new CallStackItem();
                    result.Description = "<symbol 0x" + Convert.ToString(address, 16) + " not found>";
                    items.Add(result);
                }
            }
            return(items);
        }
コード例 #3
0
        protected override List <CallStackItem> GetSymbolNamesFromAddressesInternal(List <UInt32> addresses)
        {
            string arguments = selfPath + " --addr2line=";

            for (int i = 0; i < addresses.Count; ++i)
            {
                if (i > 0)
                {
                    arguments += ",";
                }
                arguments += addresses[i].ToString();
            }

            // Start the child process.
            Process p = new Process();

            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName  = ps3BinPath;
            p.StartInfo.Arguments = arguments;
            p.Start();
            string output = p.StandardOutput.ReadToEnd();

            p.WaitForExit();

            // output looks something like this:
            // Address:       0x010C8FF4
            // Directory:     E:/perforce/depot/dev/c3/Code/CryEngine/CryScriptSystem/LuaRemoteDebug
            // File Name:     LuaRemoteDebug.cpp
            // Line Number:   571
            // Symbol:        CLuaRemoteDebug::SendLuaState(lua_Debug*)
            // Address:       0x010CA180
            // Directory:     E:/perforce/depot/dev/c3/Code/CryEngine/CryScriptSystem/LuaRemoteDebug
            // File Name:     LuaRemoteDebug.cpp
            // Line Number:   315
            // Symbol:        CLuaRemoteDebug::OnNotificationNetworkReceive(void const*, unsigned int)
            // etc...

            string[] lines = output.Split('\n');

            List <CallStackItem> items = new List <CallStackItem>();

            CallStackItem item         = new CallStackItem();
            bool          foundAddress = false;

            foreach (string line in lines)
            {
                if (line.StartsWith("Address:"))
                {
                    // The addresses should be returned in the order we requested them
                    if (foundAddress)
                    {
                        items.Add(item);
                    }
                    foundAddress = true;
                    item         = new CallStackItem();
                }
                else if (line.StartsWith("File Name:"))
                {
                    item.Source = line.Substring(line.IndexOf(':') + 1).Trim();
                }
                else if (line.StartsWith("Line Number:"))
                {
                    int.TryParse(line.Substring(line.IndexOf(':') + 1).Trim(), out item.Line);
                }
                else if (line.StartsWith("Symbol:"))
                {
                    item.Description = line.Substring(line.IndexOf(':') + 1).Trim();
                }
            }
            if (foundAddress)
            {
                items.Add(item);
            }

            if (items.Count != addresses.Count)
            {
                // Something went wrong! Just return not found symbols
                items.Clear();
                foreach (UInt32 address in addresses)
                {
                    item             = new CallStackItem();
                    item.Description = "<symbol 0x" + Convert.ToString(address, 16) + " not found>";
                    items.Add(item);
                }
            }

            return(items);
        }
コード例 #4
0
        private void ReceiveExecutionLocation(EndianBinaryReader reader)
        {
            string source = ReadString(reader);
            int    line   = reader.ReadInt32();

            // Lua callstack
            int luaCallstackLength         = reader.ReadInt32();
            List <CallStackItem> callstack = new List <CallStackItem>(luaCallstackLength);

            for (int i = 0; i < luaCallstackLength; ++i)
            {
                CallStackItem item;
                item.FrameIndex  = i;
                item.Source      = ReadString(reader);
                item.Line        = reader.ReadInt32();
                item.Description = ReadString(reader);
                if (hostVersion < 6)
                {
                    ReadString(reader);
                }
                callstack.Add(item);
            }

            if (hostVersion >= 3)
            {
                // C++ callstack
                List <string> cppCallstack       = new List <string>();
                int           cppCallstackLength = reader.ReadInt32();
                for (int i = 0; i < cppCallstackLength; ++i)
                {
                    string cppItem = ReadString(reader);
                    cppCallstack.Add(cppItem.Trim());
                }

                // For PC parse the callstack (symbols are already resolved)
                if (hostPlatform == Platform.Win32 || hostPlatform == Platform.Win64 || hostPlatform == Platform.Unknown)
                {
                    int frameIndex = luaCallstackLength;
                    foreach (string cppItem in cppCallstack)
                    {
                        CallStackItem item  = new CallStackItem();
                        Match         match = Regex.Match(cppItem, @"(.*)  \[(.*):(\d+)]");
                        if (match.Success && match.Groups.Count == 4)
                        {
                            item.Description = match.Groups[1].Value;
                            item.Source      = match.Groups[2].Value;
                            item.Line        = Int32.Parse(match.Groups[3].Value);
                        }
                        else
                        {
                            item.Description = cppItem;
                        }
                        item.FrameIndex = ++frameIndex;
                        callstack.Add(item);
                    }
                }
                // the following is removed until we have other non-pc platforms - for example, android with remote symbols:

                /*else if (hostPlatform == Platform.Xbox || hostPlatform == Platform.PS3) // ACCEPTED_USE
                 * {
                 *      // For consoles we need to resolve the symbols using the symbols manager
                 *      if (symbolsManager != null)
                 *      {
                 *              List<UInt32> addresses = new List<UInt32>();
                 *              foreach (string cppItem in cppCallstack)
                 *              {
                 *                      UInt32 address;
                 *                      if (UInt32.TryParse(cppItem, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out address))
                 *                      {
                 *                              addresses.Add(address);
                 *                      }
                 *              }
                 *              callstack.AddRange(symbolsManager.GetSymbolNamesFromAddresses(addresses));
                 *      }
                 *      else
                 *      {
                 *              foreach (string cppItem in cppCallstack)
                 *              {
                 *                      CallStackItem item = new CallStackItem();
                 *                      item.Description = "<symbol 0x" + cppItem + " unresolved>";
                 *                      callstack.Add(item);
                 *              }
                 *      }
                 * }*/
                if (cppCallStackMode == CppCallStackMode.Condensed)
                {
                    // Trim out the part of the C++ callstack down to where the LUA function is initially called
                    for (int i = luaCallstackLength; i < callstack.Count; ++i)
                    {
                        if (callstack[i].Description.Contains("lua_pcall"))
                        {
                            do
                            {
                                ++i;
                            } while (i < callstack.Count && callstack[i].Description.StartsWith("CScriptSystem::EndCall", StringComparison.OrdinalIgnoreCase));
                            callstack.RemoveRange(luaCallstackLength, i - luaCallstackLength);
                            break;
                        }
                    }
                }
            }

            if (ExecutionLocationChanged != null)
            {
                ExecutionLocationChanged(source, line, callstack);
            }
        }