// TODO: Is this sufficient? I wonder what a function pointer that returns // a function pointer looks like... protected override ColorString GetColorName() { if (null == m_colorName) { var cs = new ColorString(); cs.Append(DbgProvider.ColorizeTypeName(ReturnType.Name)); cs.Append(" (*fn)( "); if (0 == Arguments.Count) { cs.Append(DbgProvider.ColorizeTypeName("void")); cs.Append(" "); } else { for (int i = 0; i < Arguments.Count; i++) { cs.Append(DbgProvider.ColorizeTypeName(Arguments[i].ArgType.Name)); if (i < (Arguments.Count - 1)) { cs.Append(","); } cs.Append(" "); } } m_colorName = cs.Append(")").MakeReadOnly(); } return(m_colorName); } // end GetColorName()
public override ColorString ToColorString() { var cs = new ColorString().Append(DbgProvider.ColorizeModuleName(m_sym.Module.Name)) .Append("!") .Append(DbgProvider.ColorizeTypeName(m_sym.Name)); return(cs); }
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()
} // end Truncate() /// <summary> /// Creates a new ColorString object if truncation is necessary. /// </summary> public static ColorString Truncate(ColorString cs, int maxApparentWidth, bool useEllipsis) { if (cs.Length <= maxApparentWidth) { return(cs); } // Would it be better to go through all the elements? return(CaStringUtil.Truncate(cs.ToString(true), maxApparentWidth, useEllipsis)); } // end Truncate()
} // end ToString(); public ColorString ToColorString() { ColorString cs = new ColorString(); foreach (DbgStackFrameInfo frame in EnumerateStackFrames()) { cs.AppendLine(frame.ToColorString()); } return(cs); } // end ToColorString()
public ColorString AppendBgRgb(byte r, byte g, byte b, ColorString other = null) { _CheckReadOnly(true); m_elements.Add(new SgrControlSequence(new[] { 48, 2, r, g, b })); if (null == other) { return(this); } return(Append(other)); }
} // end _FormatBlocks() private ColorString _FormatCharsOnly(uint numColumns, uint bytesPerChar, Func <char, char> toDisplay) { if (0 == numColumns) { numColumns = 32; // documentation says it should be 48, but windbg seems to do 32 instead. } ColorString cs = new ColorString(); StringBuilder sbChars = new StringBuilder((int)numColumns + 8); ulong addr = StartAddress; 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 (sbChars.Length > 1) { sbChars.Append('"'); 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 * bytesPerChar; } // end start of new line // Widen to ulong to accommodate largest possible item. ulong val = (ulong)this[idx]; if (0 == val) { break; } sbChars.Append(toDisplay((char)val)); } // end for( idx = 0 .. length ) // Finish off last line. if (sbChars.Length > 1) { sbChars.Append('"'); cs.AppendPushPopFg(ConsoleColor.Cyan, sbChars.ToString()); } return(cs.MakeReadOnly()); } // end _FormatCharsOnly()
public override ColorString ToColorString() { // TODO: This is the same as the DbgNativeFunction... factor out? // Or factor Module "in"? (Because maybe not all functions would have a // module?) var cs = new ColorString().Append(DbgProvider.ColorizeModuleName(Module.Name)) .Append("!") .Append(DbgProvider.ColorizeTypeName(Name)); return(cs); }
} // end Module public override ColorString ToColorString() { ColorString cs = new ColorString(); if (null != Module) { cs.Append(DbgProvider.ColorizeModuleName(Module.Name)).Append("!"); } cs.Append(DbgProvider.ColorizeTypeName(Name)); return(cs); }
public ColorString Append(ColorString other) { if (null == other) { return(this); } _CheckReadOnly(true); m_elements.AddRange(other.m_elements); m_apparentLength += other.m_apparentLength; return(this); }
public ColorString ToColorString() { if (null == m_cs) { m_cs = new ColorString("VTable for ") .Append(OwningType.ColorName) .Append(Util.Sprintf(" (rel. offset {0}, {1} slots)", Offset, VTableShape.NumSlots)) .MakeReadOnly(); } return(m_cs); }
protected override ColorString GetColorName() { ColorString csDimensions = new ColorString(); DbgNamedTypeInfo curDti = this; while (curDti is DbgArrayTypeInfo) { var ati = (DbgArrayTypeInfo)curDti; _AppendDimension(csDimensions, ati.Count); curDti = ati.ArrayElementType; } return(new ColorString(curDti.ColorName).Append(csDimensions).MakeReadOnly()); } // end GetColorName()
/// <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()
} // end _FormatBits() private static ColorString _DefaultSymLookup(DbgEngDebugger debugger, ulong addr) { ulong disp; string symName; if (debugger.TryGetNameByOffset(addr, out symName, out disp)) { ColorString cs = DbgProvider.ColorizeSymbol(symName); if (disp != 0) { cs.AppendPushPopFg(ConsoleColor.Gray, "+" + disp.ToString("x")); } return(cs); } return(ColorString.Empty); } // end _DefaultSymLookup()
/// <summary> /// Creates a new ColorString object if any change is necessary. /// TODO: Perhaps it should /always/ create a new object? /// </summary> public static ColorString MakeFixedWidth(ColorString cs, int maxApparentWidth, bool useEllipsis, Alignment contentAlignment) { var trimLocation = TrimLocation.Right; if (Alignment.Right == contentAlignment) { trimLocation = TrimLocation.Left; } return(MakeFixedWidth(cs, maxApparentWidth, useEllipsis, contentAlignment, trimLocation)); }
} // end _FormatCharsOnly() private ColorString _FormatBits() { ColorString cs = new ColorString(); uint bytesPerValue = sizeof(uint); uint bitsPerValue = bytesPerValue * 8; ulong addr = StartAddress; for (int idx = 0; idx < Count; idx++) { if (0 != idx) { cs.AppendLine(); } cs.Append(DbgProvider.FormatAddress(addr, m_is32Bit, true, true)).Append(" "); addr += (ulong)bytesPerValue; uint val = this[idx]; for (int i = 0; i < bitsPerValue; i++) { if (i % 8 == 0) { cs.Append(" "); } uint mask = 0x80000000 >> i; if ((mask & val) == mask) { cs.AppendPushPopFg(ConsoleColor.Green, "1"); } else { cs.AppendPushPopFg(ConsoleColor.DarkGreen, "0"); } } cs.Append(" " + val.ToString("x").PadLeft(8, '0')); } // end for( idx = 0 .. length ) return(cs.MakeReadOnly()); } // end _FormatBits()
/// <summary> /// Creates a new ColorString object if any change is necessary. /// TODO: Perhaps it should /always/ create a new object? /// </summary> /// <remarks> /// Note that not all combinations of useEllipsis, contentAlignment, and /// trimLocation are valid. /// </remarks> public static ColorString MakeFixedWidth(ColorString cs, int maxApparentWidth, bool useEllipsis, Alignment contentAlignment, TrimLocation trimLocation) { if (cs.Length > maxApparentWidth) { return(Truncate(cs, maxApparentWidth, useEllipsis, trimLocation)); } else if (cs.Length == maxApparentWidth) { return(cs); } int diff = maxApparentWidth - cs.Length; switch (contentAlignment) { case Alignment.Undefined: case Alignment.Left: // Pad right: return(new ColorString(cs).Append(new String(' ', diff))); case Alignment.Right: // Pad left: return(new ColorString(new String(' ', diff)).Append(cs)); case Alignment.Center: int diff2 = diff / 2; diff = diff - diff2; return(new ColorString(new String(' ', diff2)) .Append(cs) .Append(new String(' ', diff))); default: throw new Exception("Unexpected alignment value."); } } // end MakeFixedWidth()
internal DbgDisassembly(ulong address, byte[] codeBytes, string instruction, string arguments, ColorString blockId, ColorString colorString) { if (0 == address) { throw new ArgumentOutOfRangeException("address", address, "There shouldn't be any code at address 0."); } if (String.IsNullOrEmpty(instruction)) { throw new ArgumentException("You must supply an instruction.", "instruction"); } if (String.IsNullOrEmpty(arguments)) { arguments = null; // standardize on null } if (String.IsNullOrEmpty(blockId)) { blockId = null; } if (null == colorString) { throw new ArgumentNullException("colorString"); } Address = address; CodeBytes = codeBytes; Instruction = instruction; Arguments = arguments; BlockId = blockId; m_colorString = colorString; } // constructor
private static ColorString _SummarizeModuleList(bool loadedMods, List <object> modObjList, int maxWidth) { ColorString cs = new ColorString(); if (0 == modObjList.Count) { cs.AppendPushPopFg(ConsoleColor.DarkGray, "(0 modules)"); } else { cs.Append(Util.Sprintf("{0} modules: ", modObjList.Count)); for (int i = 0; i < Math.Min(modObjList.Count, 3); i++) { if (i > 0) { cs.Append(", "); } DbgModuleInfo dmi = (DbgModuleInfo)modObjList[i]; if (loadedMods) { cs.Append(DbgProvider.ColorizeModuleName(dmi.Name)); } else { cs.Append(dmi.ImageName); } } if (modObjList.Count > 3) { cs.Append(", ..."); } } return(CaStringUtil.Truncate(cs.ToString(DbgProvider.HostSupportsColor), maxWidth)); } // end _SummarizeModuleList()
} // end ToString() public ColorString ToColorString() { ColorString cs; if (0 == InstructionPointer) { cs = new ColorString(ConsoleColor.Red, "0") .Append(" ") .AppendPushFg(ConsoleColor.Yellow) .Append("WARNING: Frame IP not in any known module. Following frames may be wrong.") .AppendPop(); } else { cs = DbgProvider.ColorizeSymbol(ToString()); if ((null != Module) && (Module.SymbolType == DEBUG_SYMTYPE.EXPORT)) { // If we only have export symbols, let's give a visual clue: cs = new ColorString().AppendPushBg(ConsoleColor.DarkRed).Append(cs).AppendPop(); } } return(cs); } // end ToColorString()
} // end property Signature private ColorString _BuildSignature() { var cs = new ColorString(); if (!IsConstructor && !IsDestructor) { cs.Append(FunctionType.ReturnType.ColorName).Append(" "); } cs.Append(ColorName).Append("("); if ((0 == FunctionType.Arguments.Count) || ((1 == FunctionType.Arguments.Count) && (0 == Util.Strcmp_OI("void", FunctionType.Arguments[0].ArgType.Name)))) { cs.Append(")"); } else { bool first = true; foreach (var fa in FunctionType.Arguments) { if (first) { first = false; } else { cs.Append(","); } cs.Append(" ").Append(fa.ArgType.ColorName); } // end foreach( arg ) cs.Append(" )"); } // end else( there are arguments ) return(cs.MakeReadOnly()); } // end GetSignature()
} // end Truncate() /// <summary> /// Creates a new ColorString object if any change is necessary. /// TODO: Perhaps it should /always/ create a new object? /// </summary> public static ColorString MakeFixedWidth(ColorString cs, int maxApparentWidth) { return(MakeFixedWidth(cs, maxApparentWidth, true)); }
public ColorString AppendLine(ColorString other) { Append(other); return(AppendLine()); }
public static ColorString operator +(ColorString a, ColorString b) { var cs = new ColorString(a); return(cs.Append(b)); }
} // 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()
/// <summary> /// Creates a new ColorString object if truncation is necessary. /// </summary> public static ColorString Truncate(ColorString cs, int maxApparentWidth) { return(ColorString.Truncate(cs, maxApparentWidth, true)); } // end Truncate()
public ColorString ToColorString() { if (DEBUG_EVENT.NONE == EventType) { return(ColorString.Empty); } ColorString csThreadId; if (0xffffffff == ThreadId) { csThreadId = new ColorString(ConsoleColor.Red, "ffffffff"); } else { csThreadId = new ColorString(m_debugger.GetUModeThreadByDebuggerId(ThreadId).Tid.ToString("x")); } ColorString cs = new ColorString(ConsoleColor.Black, ConsoleColor.White, " Last event:") .Append(" ") .Append(m_debugger.GetProcessSystemId(ProcessId).ToString("x")) .Append(".") .Append(csThreadId) .Append(": "); DbgModuleInfo mod = null; string tmp = null; string[] lines = null; switch (EventType) { case DEBUG_EVENT.NONE: Util.Fail("can't get here"); // we returned ColorString.Empty above break; case DEBUG_EVENT.BREAKPOINT: cs.Append(Description); break; case DEBUG_EVENT.EXCEPTION: tmp = ExceptionEventArgs._CreateMessage(m_debugger, ExtraInformation.Exception.ExceptionRecord, ExtraInformation.Exception.FirstChance != 0, 0, null, false).ToString(DbgProvider.HostSupportsColor); lines = tmp.Split(sm_newline, StringSplitOptions.None); cs.AppendLine(lines[0]); for (int i = 1; i < lines.Length; i++) { cs.AppendPushPopFgBg(ConsoleColor.Black, ConsoleColor.White, " ") .Append(" ") .Append(lines[i]); if (i != lines.Length - 1) { cs.AppendLine(); } } break; case DEBUG_EVENT.CREATE_THREAD: cs.Append(Description); break; case DEBUG_EVENT.EXIT_THREAD: cs.Append(Description); break; case DEBUG_EVENT.CREATE_PROCESS: cs.Append(Description); break; case DEBUG_EVENT.EXIT_PROCESS: cs.Append(Description); break; case DEBUG_EVENT.LOAD_MODULE: // // Last event: 9c84.3984: Load module C:\WINDOWS\system32\ADVAPI32.dll at 00007ffb`b0cd0000 // debugger time: Mon Oct 20 19:30:56.164 2014 (UTC - 7:00) mod = m_debugger.GetModuleByAddress(ExtraInformation.LoadModule.Base); cs.Append("Loaded module ") .AppendPushPopFg(ConsoleColor.White, mod.ImageName) .Append(" at ") .Append(DbgProvider.FormatAddress(ExtraInformation.LoadModule.Base, m_debugger.TargetIs32Bit, true)); break; case DEBUG_EVENT.UNLOAD_MODULE: // TODO: test this! mod = m_debugger.GetModuleByAddress(ExtraInformation.UnloadModule.Base); cs.AppendPushPopFg(ConsoleColor.DarkRed, "Unloaded module ") .AppendPushPopFg(ConsoleColor.White, mod.ImageName) .Append(" at ") .Append(DbgProvider.FormatAddress(ExtraInformation.UnloadModule.Base, m_debugger.TargetIs32Bit, true)); break; case DEBUG_EVENT.SYSTEM_ERROR: // TODO: test this! cs.AppendPushPopFgBg(ConsoleColor.White, ConsoleColor.Red, "System error:") .Append(" ") .AppendPushPopFg(ConsoleColor.Red, Util.FormatErrorCode(ExtraInformation.SystemError.Error)) .Append(".") .AppendPushPopFg(ConsoleColor.Red, Util.FormatErrorCode(ExtraInformation.SystemError.Level)); // TODO: This is a hack. var w32e = new System.ComponentModel.Win32Exception((int)ExtraInformation.SystemError.Error); cs.AppendLine(); cs.AppendPushPopFg(ConsoleColor.Red, w32e.Message).Append("."); break; case DEBUG_EVENT.SESSION_STATUS: // DbgEng doesn't save these as "last events". Util.Fail(Util.Sprintf("Unexpected last event type: {0}", EventType)); break; case DEBUG_EVENT.CHANGE_DEBUGGEE_STATE: // DbgEng doesn't save these as "last events". Util.Fail(Util.Sprintf("Unexpected last event type: {0}", EventType)); break; case DEBUG_EVENT.CHANGE_ENGINE_STATE: // DbgEng doesn't save these as "last events". Util.Fail(Util.Sprintf("Unexpected last event type: {0}", EventType)); break; case DEBUG_EVENT.CHANGE_SYMBOL_STATE: // DbgEng doesn't save these as "last events". Util.Fail(Util.Sprintf("Unexpected last event type: {0}", EventType)); break; default: Util.Fail(Util.Sprintf("Unexpected event type: {0}", EventType)); throw new Exception(Util.Sprintf("Unexpected event type: {0}", EventType)); } // end switch( event type ) cs.AppendLine() .AppendPushPopFgBg(ConsoleColor.Black, ConsoleColor.White, " Debugger time:") .Append(" ") .Append(DbgProvider.FormatTimestamp(_GetDbgEngLastEventTimestamp(), true)); return(cs); } // end ToColorString()
/// <summary> /// Creates a new ColorString object if any change is necessary. /// TODO: Perhaps it should /always/ create a new object? /// </summary> public static ColorString MakeFixedWidth(ColorString cs, int maxApparentWidth, bool useEllipsis) { return(MakeFixedWidth(cs, maxApparentWidth, useEllipsis, Alignment.Left)); }
public ColorString(ColorString other) { Append(other); }
/// <summary> /// Creates a new ColorString object if any change is necessary. /// TODO: Perhaps it should /always/ create a new object? /// </summary> public static ColorString MakeFixedWidth(ColorString cs, int maxApparentWidth, Alignment contentAlignment) { return(MakeFixedWidth(cs, maxApparentWidth, true, contentAlignment)); }