Example #1
0
        // this is inefficient so we try and grab everything in one gulp
        internal async Task <IEnumerable <DisasmInstruction> > Disassemble(DebuggedProcess process, string file, uint line, uint dwInstructions)
        {
            if (file.IndexOf(' ') >= 0) // only needs escaping if filename contains a space
            {
                file = process.EscapeSymbolPath(file);
            }
            string  cmd     = "-data-disassemble -f " + file + " -l " + line.ToString(CultureInfo.InvariantCulture) + " -n " + dwInstructions.ToString(CultureInfo.InvariantCulture) + " -- 1";
            Results results = await process.CmdAsync(cmd, ResultClass.None);

            if (results.ResultClass != ResultClass.done)
            {
                return(null);
            }

            return(DecodeSourceAnnotatedDisassemblyInstructions(process, results.Find <ResultListValue>("asm_insns").FindAll <TupleValue>("src_and_asm_line")));
        }
Example #2
0
        private async Task <SourceLineMap> LinesForFile(string file)
        {
            string  cmd     = "-symbol-list-lines " + _process.EscapeSymbolPath(file);
            Results results = await _process.CmdAsync(cmd, ResultClass.None);

            if (results.ResultClass != ResultClass.done)
            {
                return(null);
            }

            ValueListValue lines    = results.Find <ValueListValue>("lines");
            SourceLineMap  linesMap = new SourceLineMap(lines.Content.Length);

            for (int i = 0; i < lines.Content.Length; ++i)
            {
                ulong addr = lines.Content[i].FindAddr("pc");
                uint  line = lines.Content[i].FindUint("line");

                if (linesMap.ContainsKey(addr))
                {
                    // It is actually fairly common for an address to map to more than one line. For instance,
                    // in debug builds destructors can have an entry to line 0 as well as one to the correct line.
                    // Release builds with inlining will hit this very often.
                    // Unforunately, without more context, it is impossible to know which line is the "right" line.
                    // For the inline case, any line will be acceptable. For the destructor case, we should prefer
                    // a non-zero line.
                    if (linesMap[addr].Line == 0)
                    {
                        linesMap.Replace(addr, line);
                    }
                }
                else
                {
                    linesMap.Add(addr, line);
                }
            }
            return(linesMap);
        }