コード例 #1
0
            public ColorString ToColorString()
            {
                if (null == m_cs)
                {
                    m_cs = new ColorString();
                    m_cs.Append(DbgProvider.ColorizeModuleName(m_udt.Module.Name))
                    .Append("!")
                    .Append(m_udt.ColorName)
                    .Append(" (size 0x")
                    .Append(m_udt.Size.ToString("x"))
                    .Append(")");

                    int widest = 16;
                    foreach (var item in Items)
                    {
                        var ddti = item.Item as DbgDataTypeInfo;
                        if (null != ddti)
                        {
                            widest = Math.Max(widest, ddti.Name.Length);
                        }
                    }

                    widest = Math.Min(widest, 40);

                    foreach (var item in Items)
                    {
                        m_cs.AppendLine()
                        .Append("   +0x")
                        .Append(item.Offset.ToString("x3"))
                        .Append(" ");

                        var ddti = item.Item as DbgDataTypeInfo;
                        if (null != ddti)
                        {
                            m_cs.Append(ColorString.MakeFixedWidth(ddti.Name, widest))
                            .Append(" : ")
                            .Append(ddti.DataType.ColorName);
                        }
                        else
                        {
                            VTableLayoutItem vli = (VTableLayoutItem)item;
                            var dvti             = (DbgVTableTypeInfo)item.Item;
                            m_cs.AppendPushFg(ConsoleColor.DarkGray);

                            if (vli.VTablePath.Count > 1)
                            {
                                m_cs.Append(vli.VTablePath[1].ColorName).Append(": ");
                            }
                            m_cs.Append(dvti.ToColorString())
                            .AppendPop();
                        }
                    }

                    m_cs.MakeReadOnly();
                } // end if( !m_cs )
                return(m_cs);
            }     // end ToColorString()
コード例 #2
0
        /// <summary>
        ///    Zero-pads the given value to the specified [string] length. Highlights the
        ///    non-zero portion in Green.
        /// </summary>
        private static ColorString _ZeroPad(ulong val, int desiredLen)
        {
            ColorString cs = null;

            // We need a special case for ulongs to put the ` in.
            if (16 == desiredLen)
            {
                ulong hi = (val & 0xffffffff00000000) >> 32;
                ulong lo = val & 0x00000000ffffffff;

                cs = _ZeroPad(hi, 8);

                // If 'hi' is non-zero, force the bottom half to also be highlighted, even
                // if the bottom half is all zeroes.
                if (0 != hi)
                {
                    cs.AppendPushFg(ConsoleColor.Green);
                }

                cs.Append("`");
                cs.Append(_ZeroPad(lo, 8));

                if (0 != hi)
                {
                    cs.AppendPop();
                }

                return(cs);
            }

            if (0 == val)
            {
                return(new String('0', desiredLen));
            }

            string noLeadingZeroes = val.ToString("x");

            if (noLeadingZeroes.Length == desiredLen)
            {
                return(new ColorString(ConsoleColor.Green, noLeadingZeroes));
            }

            Util.Assert(desiredLen > noLeadingZeroes.Length);

            cs = new ColorString(new String('0', desiredLen - noLeadingZeroes.Length));
            cs.AppendPushPopFg(ConsoleColor.Green, noLeadingZeroes);
            return(cs);
        } // end _ZeroPad()
コード例 #3
0
        } // end _ZeroPad()

        private ColorString _FormatBlocks(int elemSize,
                                          int charsPerBlock,
                                          uint numColumns,
                                          AddtlInfo addtlInfo)
        {
            if (0 == numColumns)
            {
                numColumns = (uint)(16 / elemSize);
            }

            if (addtlInfo.HasFlag(AddtlInfo.Symbols))
            {
                numColumns = 1;
            }

            int           desiredLen = elemSize * 2;
            ColorString   cs         = new ColorString();
            StringBuilder sbChars    = new StringBuilder(20);
            ulong         addr       = StartAddress;

            cs.AppendPushFg(ConsoleColor.DarkGreen);

            for (int idx = 0; idx < Count; idx++)
            {
                if (0 == (idx % numColumns))
                {
                    // This is the beginning of a new line.

                    // First finish off the last line if necessary:
                    if (addtlInfo.HasFlag(AddtlInfo.Ascii))
                    {
                        if (sbChars.Length > 2)
                        {
                            cs.AppendPushPopFg(ConsoleColor.Cyan, sbChars.ToString());
                        }

                        sbChars.Clear();
                        sbChars.Append("  ");
                    }

                    if (0 != idx)
                    {
                        cs.AppendLine();
                    }

                    cs.Append(DbgProvider.FormatAddress(addr, m_is32Bit, true, true)).Append("  ");
                    addr += (ulong)(numColumns * elemSize);
                } // end start of new line
                else
                {
                    cs.Append(" ");
                }

                // Widen to ulong to accommodate largest possible item.
                ulong val = (ulong)this[idx];

                // This highlights the non-zero portion in [bright] green.
                cs.Append(_ZeroPad(val, desiredLen));

                if (addtlInfo.HasFlag(AddtlInfo.Symbols))
                {
                    ColorString csSym = ColorString.Empty;
                    if (val > 4096)  // don't even bother trying if it's too low.
                    {
                        csSym = m_lookupSymbol(val);
                        if (csSym.Length > 0)
                        {
                            cs.Append(" ").Append(csSym);
                        }
                    }
                    if (addtlInfo.HasFlag(AddtlInfo.Ascii))
                    {
                        if (0 == csSym.Length)
                        {
                            cs.Append("                                          ");
                            _AppendChars(sbChars, idx * elemSize, elemSize);
                        }
                    }
                } // end if( symbols )
                else if (addtlInfo.HasFlag(AddtlInfo.Ascii))
                {
                    _AppendChars(sbChars, idx * elemSize, elemSize);
                } // end else if( Ascii )
            }     // end for( idx = 0 .. length )

            // Finish off last line.
            if (sbChars.Length > 2)
            {
                // It could be a partial line, so we may need to adjust for that.
                int numMissing = (int)numColumns - ((sbChars.Length - 2) / elemSize);
                Util.Assert(numMissing >= 0);
                if (numMissing > 0)
                {
                    cs.Append(new String(' ', numMissing * charsPerBlock));
                }
                cs.AppendPushPopFg(ConsoleColor.Cyan, sbChars.ToString());
            }

            cs.AppendPop(); // pop DarkGreen

            return(cs.MakeReadOnly());
        } // end _FormatBlocks()