Esempio n. 1
0
        private void renderSymbolDetail(DebugSymbolEntry entry)
        {
            Tag tag = null;

            if (file_.Tags != null)
            {
                tag = file_.Tags.FindTag(entry.TagId);
            }

            startDetail("; {0}", entry.Name);
            if (entry.Address < 0)
            {
                addDetailLine("address = -0x{0:x}", -entry.Address);
            }
            else
            {
                addDetailLine("address = 0x{0:x}", entry.Address);
            }
            if (tag == null)
            {
                addDetailLine("tagid = 0x{0:x}", entry.TagId);
            }
            else
            {
                addDetailLine("tagid = 0x{0:x} ; {1}", entry.TagId, tag.Name);
            }
            addDetailLine("codestart = 0x{0:x}", entry.CodeStart);
            addDetailLine("codeend = 0x{0:x}", entry.CodeEnd);
            addDetailLine("nameoffs = 0x{0:x} ; {1}", entry.nameoffs, entry.Name);
            addDetailLine("kind = {0:d} ; {1}", entry.Ident, entry.Ident.ToString());
            addDetailLine("scope = {0:d} ; {1}", entry.Scope, entry.Scope.ToString());

            if (entry.Dims != null)
            {
                addDetailLine("dims = {0}", dimsToString(tag, entry.Dims));
            }

            string file = null;

            if (file_.DebugFiles != null)
            {
                file = file_.DebugFiles.FindFile(entry.CodeStart);
            }
            if (file != null)
            {
                addDetailLine("file: \"{0}\"", (string)file);
            }

            uint?line = null;

            if (file_.DebugLines != null)
            {
                line = file_.DebugLines.FindLine(entry.CodeStart);
            }
            if (line != null)
            {
                addDetailLine("line: \"{0}\"", (uint)line);
            }
            endDetailUpdate();
        }
Esempio n. 2
0
        private void renderDebugFunction(SmxDebugSymbolsTable syms, TreeNode root, DebugSymbolEntry fun)
        {
            root.Tag = new NodeData(delegate()
            {
                renderSymbolDetail(fun);
            }, null);

            var args   = new List <DebugSymbolEntry>();
            var locals = new List <DebugSymbolEntry>();

            foreach (var sym_ in syms.Entries)
            {
                var sym = sym_;
                if (sym.Scope == SymScope.Global)
                {
                    continue;
                }
                if (sym.CodeStart < fun.CodeStart || sym.CodeEnd > fun.CodeEnd)
                {
                    continue;
                }
                if (sym.Address < 0)
                {
                    locals.Add(sym);
                }
                else
                {
                    args.Add(sym);
                }
            }

            args.Sort(delegate(DebugSymbolEntry e1, DebugSymbolEntry e2)
            {
                return(e1.Address.CompareTo(e2.Address));
            });
            foreach (var sym_ in args)
            {
                var sym  = sym_;
                var node = root.Nodes.Add(sym.Name);
                node.Tag = new NodeData(delegate()
                {
                    renderSymbolDetail(sym);
                }, null);
            }

            locals.Sort(delegate(DebugSymbolEntry e1, DebugSymbolEntry e2)
            {
                return(e1.CodeStart.CompareTo(e2.CodeStart));
            });
            foreach (var sym_ in locals)
            {
                var sym  = sym_;
                var node = root.Nodes.Add(sym.Name);
                node.Tag = new NodeData(delegate()
                {
                    renderSymbolDetail(sym);
                }, null);
            }
        }
Esempio n. 3
0
        private void renderCodeView(SmxCodeV1Section code, string name, int address)
        {
            startDetailUpdate();

            V1Instruction[] insns;
            try
            {
                insns = V1Disassembler.Disassemble(file_, code, address);
            }
            catch (Exception e)
            {
                addDetailLine("Could not disassemble method {0}: {1}", name, e.Message);
                endDetailUpdate();
                return;
            }

            addDetailLine("; {0}", name);
            addDetailLine("; {0} instruction(s)", insns.Length);
            addDetailLine("; starts at code address 0x{0:x}", address);
            addDetailLine("---");

            if (insns.Length == 0)
            {
                endDetailUpdate();
                return;
            }


            // Find the largest address so we can get consistent column length.
            int last_address = insns[insns.Length - 1].Address;
            var ndigits      = string.Format("{0:x}", last_address).Length;
            var addrfmt      = "0x{0:x" + ndigits + "}: ";

            var buffer  = new StringBuilder();
            var comment = new StringBuilder();

            foreach (var insn in insns)
            {
                buffer.Clear();
                comment.Clear();
                buffer.Append(insn.Info.Name);

                for (var i = 0; i < insn.Params.Length; i++)
                {
                    if (i >= insn.Info.Params.Length)
                    {
                        break;
                    }
                    var kind  = insn.Info.Params[i];
                    var value = insn.Params[i];

                    switch (kind)
                    {
                    case V1Param.Constant:
                    case V1Param.CaseTable:
                        buffer.Append(string.Format(" 0x{0:x}", value));
                        comment.Append(string.Format(" {0}", value));
                        break;

                    case V1Param.Native:
                        buffer.Append(string.Format(" {0}", value));
                        if (file_.Natives != null && value < file_.Natives.Length)
                        {
                            comment.Append(string.Format(" {0}", file_.Natives[value].Name));
                        }
                        break;

                    case V1Param.Jump:
                        int delta = value - insn.Address;
                        buffer.Append(string.Format(" 0x{0:x}", value));
                        if (delta >= 0)
                        {
                            comment.Append(string.Format(" +0x{0:x}", delta));
                        }
                        else
                        {
                            comment.Append(string.Format(" -0x{0:x}", -delta));
                        }
                        break;

                    case V1Param.Address:
                    {
                        DebugSymbolEntry sym = null;
                        if (file_.DebugSymbols != null)
                        {
                            sym = file_.DebugSymbols.FindDataRef(value);
                        }
                        buffer.Append(string.Format(" 0x{0:x}", value));
                        if (sym != null)
                        {
                            comment.Append(string.Format(" {0}", sym.Name));
                        }
                        else
                        {
                            comment.Append(string.Format(" {0}", value));
                        }
                        break;
                    }

                    case V1Param.Stack:
                    {
                        DebugSymbolEntry sym = null;
                        if (file_.DebugSymbols != null)
                        {
                            sym = file_.DebugSymbols.FindStackRef(insn.Address, value);
                        }
                        buffer.Append(string.Format(" 0x{0:x}", value));
                        if (sym != null)
                        {
                            comment.Append(string.Format(" {0}", sym.Name));
                        }
                        else
                        {
                            comment.Append(string.Format(" {0}", value));
                        }
                        break;
                    }

                    case V1Param.Function:
                        string fun = file_.FindFunctionName(value);
                        buffer.Append(string.Format(" 0x{0:x}", value));
                        comment.Append(string.Format(" {0}", fun));
                        break;
                    }
                }

                detail_buffer_.Append(string.Format(addrfmt, insn.Address));
                detail_buffer_.Append(string.Format("{0,-32}", buffer));
                if (comment.Length > 0)
                {
                    detail_buffer_.Append(string.Format(" ;{1}", buffer, comment));
                }
                detail_buffer_.Append("\r\n");
            }

            endDetailUpdate();
        }