private static void InsertElement(ElementGroup line, Element el, Graphics gfx, ref PointF pt, float preX, float postX) { line.Add(el); pt.X += preX; pt = el.Prepare(gfx, pt); pt.X += postX; }
private static void InsertElement( ElementGroup line, Element el, Graphics gfx, ref PointF pt, float preX, float postX ) { line.Add( el ); pt.X += preX; pt = el.Prepare( gfx, pt ); pt.X += postX; }
protected override void OnPaint(PaintEventArgs pe) { if (m_mh == null) { return; } int width = this.Width; int height = this.Height; if (m_bm == null || m_bm.Width != width || m_bm.Height != height) { m_bm = new Bitmap(width, height); Graphics gfx = Graphics.FromImage(m_bm); Font f = this.Font; int rows = (height + f.Height - 1) / f.Height; uint address = m_address; MemoryHandler.Region data = m_mh.ReadRegion(address, m_addressIncrement * rows); int pos; m_elements = new ElementGroup(); gfx.Clear(Color.White); for (float y = 0; y < height; address += (uint)m_addressIncrement) { Element el = (Element)m_elementsMemory[address]; if (el == null) { ElementGroup line = new ElementGroup(); PointF pt = new PointF(0, 0); string symbol; uint val32; ushort val16; byte val8; symbol = m_symbols_AddressToString[address] as string; if (symbol != null) { el = new TextElement(f, Brushes.Purple, String.Format("{0}:", symbol)); line.Add(el); pt.Y += 2; pt = el.Prepare(gfx, pt); pt.X = 0; pt.Y += f.Height; } el = new AddressElement(f, Brushes.Red, address); InsertElement(line, el, gfx, ref pt, 0, 6); switch (m_viewMode) { case ViewMode.Words: case ViewMode.Disassembly: for (pos = 0; pos < m_addressIncrement; pos += 4) { if (data.GetWord((uint)(address + pos), out val32)) { el = new WordElement(f, Brushes.Black, val32); } else { el = new TextElement(f, Brushes.Black, "XXXXXXXX"); } InsertElement(line, el, gfx, ref pt, 0, 6); } break; case ViewMode.Shorts: for (pos = 0; pos < m_addressIncrement; pos += 2) { if (data.GetShort((uint)(address + pos), out val16)) { el = new ShortElement(f, Brushes.Black, val16); } else { el = new TextElement(f, Brushes.Black, "XXXX"); } InsertElement(line, el, gfx, ref pt, 0, 6); } break; case ViewMode.Bytes: for (pos = 0; pos < m_addressIncrement; pos += 1) { if (data.GetByte((uint)(address + pos), out val8)) { el = new ByteElement(f, Brushes.Black, val8); } else { el = new TextElement(f, Brushes.Black, "XX"); } InsertElement(line, el, gfx, ref pt, 0, 6); } break; case ViewMode.HeapBlocks: for (pos = 0; pos < m_addressIncrement; pos += 4) { if (data.GetWord((uint)(address + pos), out val32)) { el = new WordElement(f, Brushes.Black, val32); } else { el = new TextElement(f, Brushes.Black, "XXXXXXXX"); } InsertElement(line, el, gfx, ref pt, 0, 6); } break; } el = new CharsElement(f, Brushes.Blue, data, address, m_addressIncrement); InsertElement(line, el, gfx, ref pt, 10, 10); if (m_viewMode == ViewMode.Disassembly) { uint res; if (data.GetWord(address, out res)) { string str; uint target = 0; bool targetIsCode = false; try { str = _DBG.ArmDisassembler.DecodeAndPrint(address, res, ref target, ref targetIsCode); } catch { str = null; } el = new TextElement(f, Brushes.Maroon, str); if (target != 0xFFFFFFFF) { el.Value = target; } InsertElement(line, el, gfx, ref pt, 0, 6); symbol = m_symbols_AddressToString[target] as string; if (symbol != null) { el = new TextElement(f, Brushes.Purple, String.Format("{0}", symbol)); el.Value = target; InsertElement(line, el, gfx, ref pt, 0, 0); } else if (target != 0xFFFFFFFF && targetIsCode == false) { MemoryHandler.Region data2 = m_mh.ReadRegion(target, 4); if (data2.GetWord(target, out res)) { el = new TextElement(f, Brushes.Purple, String.Format("= #0x{0,8:X8}", res)); el.Value = res; InsertElement(line, el, gfx, ref pt, 0, 0); } } } } else if (m_viewMode == ViewMode.HeapBlocks) { if (data.GetWord(address, out val32)) { uint dt = (val32 >> 0) & 0x00FF; uint flags = (val32 >> 8) & 0x00FF; uint size = (val32 >> 16) & 0xFFFF; if (dt > (uint)_DBG.RuntimeDataType.DATATYPE_STACK_FRAME) { dt++; } if (dt >= (uint)_DBG.RuntimeDataType.DATATYPE_FIRST_INVALID) { el = new TextElement(f, Brushes.Red, String.Format("Invalid data type: {0}", dt)); } else { el = new TextElement(f, Brushes.DarkGreen, String.Format("{0} {1} Size:{2} Next:{3,8:X8}", (_DBG.RuntimeDataType)dt, flags, size, address + size * 12)); el.Value = (uint)(address + size * 12); } InsertElement(line, el, gfx, ref pt, 10, 6); } } m_elementsMemory[address] = line; el = line; } el.SetOrigin(0, y); m_elements.Add(el); y += el.Bounds.Bottom; if (m_selected == null) { foreach (Element el2 in el) { if (el2 is AddressElement && el2.Value.Equals(m_selectedAddress)) { m_selected = el2; m_selected.Selected = true; break; } } } } m_elements.Draw(gfx); } pe.Graphics.DrawImage(m_bm, 0, 0); }
protected override void OnPaint( PaintEventArgs pe ) { if(m_mh == null) return; int width = this.Width; int height = this.Height; if(m_bm == null || m_bm.Width != width || m_bm.Height != height) { m_bm = new Bitmap( width, height ); Graphics gfx = Graphics.FromImage( m_bm ); Font f = this.Font; int rows = (height + f.Height - 1) / f.Height; uint address = m_address; MemoryHandler.Region data = m_mh.ReadRegion( address, m_addressIncrement * rows ); int pos; m_elements = new ElementGroup(); gfx.Clear( Color.White ); for(float y = 0; y < height; address += (uint)m_addressIncrement) { Element el = (Element)m_elementsMemory[ address ]; if(el == null) { ElementGroup line = new ElementGroup(); PointF pt = new PointF( 0, 0 ); string symbol; uint val32; ushort val16; byte val8; symbol = m_symbols_AddressToString[ address ] as string; if(symbol != null) { el = new TextElement( f, Brushes.Purple, String.Format( "{0}:", symbol ) ); line.Add( el ); pt.Y += 2; pt = el.Prepare( gfx, pt ); pt.X = 0; pt.Y += f.Height; } el = new AddressElement( f, Brushes.Red, address ); InsertElement( line, el, gfx, ref pt, 0, 6 ); switch(m_viewMode) { case ViewMode.Words: case ViewMode.Disassembly: for(pos=0; pos<m_addressIncrement; pos+=4) { if(data.GetWord( (uint)(address + pos), out val32 )) { el = new WordElement( f, Brushes.Black, val32 ); } else { el = new TextElement( f, Brushes.Black, "XXXXXXXX" ); } InsertElement( line, el, gfx, ref pt, 0, 6 ); } break; case ViewMode.Shorts: for(pos=0; pos<m_addressIncrement; pos+=2) { if(data.GetShort( (uint)(address + pos), out val16 )) { el = new ShortElement( f, Brushes.Black, val16 ); } else { el = new TextElement( f, Brushes.Black, "XXXX" ); } InsertElement( line, el, gfx, ref pt, 0, 6 ); } break; case ViewMode.Bytes: for(pos=0; pos<m_addressIncrement; pos+=1) { if(data.GetByte( (uint)(address + pos), out val8 )) { el = new ByteElement( f, Brushes.Black, val8 ); } else { el = new TextElement( f, Brushes.Black, "XX" ); } InsertElement( line, el, gfx, ref pt, 0, 6 ); } break; case ViewMode.HeapBlocks: for(pos=0; pos<m_addressIncrement; pos+=4) { if(data.GetWord( (uint)(address + pos), out val32 )) { el = new WordElement( f, Brushes.Black, val32 ); } else { el = new TextElement( f, Brushes.Black, "XXXXXXXX" ); } InsertElement( line, el, gfx, ref pt, 0, 6 ); } break; } el = new CharsElement( f, Brushes.Blue, data, address, m_addressIncrement ); InsertElement( line, el, gfx, ref pt, 10, 10 ); if(m_viewMode == ViewMode.Disassembly) { uint res; if(data.GetWord( address, out res )) { string str; uint target = 0; bool targetIsCode = false; try { str = _DBG.ArmDisassembler.DecodeAndPrint( address, res, ref target, ref targetIsCode ); } catch { str = null; } el = new TextElement( f, Brushes.Maroon, str ); if(target != 0xFFFFFFFF) { el.Value = target; } InsertElement( line, el, gfx, ref pt, 0, 6 ); symbol = m_symbols_AddressToString[ target ] as string; if(symbol != null) { el = new TextElement( f, Brushes.Purple, String.Format( "{0}", symbol ) ); el.Value = target; InsertElement( line, el, gfx, ref pt, 0, 0 ); } else if(target != 0xFFFFFFFF && targetIsCode == false) { MemoryHandler.Region data2 = m_mh.ReadRegion( target, 4 ); if(data2.GetWord( target, out res )) { el = new TextElement( f, Brushes.Purple, String.Format( "= #0x{0,8:X8}", res ) ); el.Value = res; InsertElement( line, el, gfx, ref pt, 0, 0 ); } } } } else if(m_viewMode == ViewMode.HeapBlocks) { if(data.GetWord( address, out val32 )) { uint dt = (val32 >> 0) & 0x00FF; uint flags = (val32 >> 8) & 0x00FF; uint size = (val32 >> 16) & 0xFFFF; if(dt > (uint)_DBG.RuntimeDataType.DATATYPE_STACK_FRAME) dt++; if(dt >= (uint)_DBG.RuntimeDataType.DATATYPE_FIRST_INVALID) { el = new TextElement( f, Brushes.Red, String.Format( "Invalid data type: {0}", dt ) ); } else { el = new TextElement( f, Brushes.DarkGreen, String.Format( "{0} {1} Size:{2} Next:{3,8:X8}", (_DBG.RuntimeDataType)dt, flags, size, address + size * 12 ) ); el.Value = (uint)(address + size * 12); } InsertElement( line, el, gfx, ref pt, 10, 6 ); } } m_elementsMemory[ address ] = line; el = line; } el.SetOrigin( 0, y ); m_elements.Add( el ); y += el.Bounds.Bottom; if(m_selected == null) { foreach(Element el2 in el) { if(el2 is AddressElement && el2.Value.Equals( m_selectedAddress )) { m_selected = el2; m_selected.Selected = true; break; } } } } m_elements.Draw( gfx ); } pe.Graphics.DrawImage( m_bm, 0, 0 ); }