internal Chunk(MemorySnapshot.MemoryBlock mb) { int len = mb.m_data.Length; m_address = mb.m_address; m_data = new short[len]; for (int i = 0; i < len; i++) { m_data[i] = mb.m_data[i]; } }
private void button_DebugOffline_Click(object sender, System.EventArgs e) { try { using(System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog()) { dlg.Filter = "Snapshot files (*.spodump)|*.spodump|SREC format (*.hex)|*.hex"; dlg.Title = "Load snapshot from a file"; if(dlg.ShowDialog() == DialogResult.OK) { if(dlg.FilterIndex == 1) { using(FileStream s = new FileStream( dlg.FileName, FileMode.Open, FileAccess.Read )) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter fmt = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); m_snapshot = (MemorySnapshot)fmt.Deserialize( s ); if(m_snapshot.m_block_FLASH == null) { DialogResult res = MessageBox.Show( "No FLASH image in the dump.\nDo you want to connect to a device?", "Snapshot", MessageBoxButtons.YesNoCancel ); if(res == DialogResult.Cancel) { m_snapshot = new MemorySnapshot(); return; } if(res == DialogResult.Yes) { if(Connect() == false) { return; } } } } } else { ArrayList blocks = new ArrayList(); uint entrypoint = Microsoft.SPOT.Debugger.SRecordFile.Parse( dlg.FileName, blocks, null ); MemorySnapshot.MemoryBlock blk = new MemorySnapshot.MemoryBlock(); m_snapshot = new MemorySnapshot(); m_snapshot.m_block_FLASH = blk; foreach(_DBG.SRecordFile.Block bl in blocks) { blk.m_address = bl.address; blk.m_data = bl.data.ToArray(); } m_snapshot.m_registers[15] = blk.m_address; } this.Close(); } } } catch(Exception ex) { MessageBox.Show( ex.Message ); } }
private void TakeSnapshot_Worker() { try { int size; if(m_snapshot_RAM) { MemorySnapshot.MemoryBlock mb = new MemorySnapshot.MemoryBlock(); mb.m_address = m_snapshot.m_ramBase; size = ProbeMemory( mb.m_address, (int)m_snapshot.m_ramSize, 128 * 1024 ); mb.m_data = new byte[size]; if(GetMemory( mb.m_address, mb.m_data, 0, size, "Loading RAM" ) != size) { // ?? } m_snapshot.m_block_RAM = mb; } else { m_snapshot.m_block_RAM = null; } if(m_snapshot_FLASH) { MemorySnapshot.MemoryBlock mb = new MemorySnapshot.MemoryBlock(); mb.m_address = m_snapshot.m_flashBase; size = ProbeMemory( mb.m_address, (int)m_snapshot.m_flashSize, 1024 * 1024 ); mb.m_data = new byte[size]; if(GetMemory( mb.m_address, mb.m_data, 0, size, "Loading FLASH" ) != size) { // ?? } m_snapshot.m_block_FLASH = mb; } else { m_snapshot.m_block_FLASH = null; } try { using(FileStream s = new FileStream( m_snapshot_File, FileMode.Create, FileAccess.Write )) { if(m_snapshot_Kind == 1) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter fmt = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); fmt.Serialize( s, m_snapshot ); } else { BinaryWriter writer = new BinaryWriter( s ); writer.Write( (uint)0xDEADBEEF ); if(m_snapshot_RAM) { MemorySnapshot.MemoryBlock mb = m_snapshot.m_block_RAM; writer.Write( mb.m_address ); writer.Write( (uint)mb.m_data.Length ); writer.Write( mb.m_data, 0, mb.m_data.Length ); } if(m_snapshot_FLASH) { MemorySnapshot.MemoryBlock mb = m_snapshot.m_block_FLASH; writer.Write( mb.m_address ); writer.Write( (uint)mb.m_data.Length ); writer.Write( mb.m_data, 0, mb.m_data.Length ); } writer.Flush(); } s.Flush(); } } catch { } } finally { try { Disconnect(); } catch { } m_worker = null; labelStatus .Text = ""; progressBarDownload.Value = 0; SetControlsStatus( true ); } }
private void button_DebugOffline_Click(object sender, System.EventArgs e) { try { using (System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog()) { dlg.Filter = "Snapshot files (*.spodump)|*.spodump|SREC format (*.hex)|*.hex"; dlg.Title = "Load snapshot from a file"; if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.FilterIndex == 1) { using (FileStream s = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read)) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter fmt = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); m_snapshot = (MemorySnapshot)fmt.Deserialize(s); if (m_snapshot.m_block_FLASH == null) { DialogResult res = MessageBox.Show("No FLASH image in the dump.\nDo you want to connect to a device?", "Snapshot", MessageBoxButtons.YesNoCancel); if (res == DialogResult.Cancel) { m_snapshot = new MemorySnapshot(); return; } if (res == DialogResult.Yes) { if (Connect() == false) { return; } } } } } else { ArrayList blocks = new ArrayList(); uint entrypoint = Microsoft.SPOT.Debugger.SRecordFile.Parse(dlg.FileName, blocks, null); MemorySnapshot.MemoryBlock blk = new MemorySnapshot.MemoryBlock(); m_snapshot = new MemorySnapshot(); m_snapshot.m_block_FLASH = blk; foreach (_DBG.SRecordFile.Block bl in blocks) { blk.m_address = bl.address; blk.m_data = bl.data.ToArray(); } m_snapshot.m_registers[15] = blk.m_address; } this.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void TakeSnapshot_Worker() { try { int size; if (m_snapshot_RAM) { MemorySnapshot.MemoryBlock mb = new MemorySnapshot.MemoryBlock(); mb.m_address = m_snapshot.m_ramBase; size = ProbeMemory(mb.m_address, (int)m_snapshot.m_ramSize, 128 * 1024); mb.m_data = new byte[size]; if (GetMemory(mb.m_address, mb.m_data, 0, size, "Loading RAM") != size) { // ?? } m_snapshot.m_block_RAM = mb; } else { m_snapshot.m_block_RAM = null; } if (m_snapshot_FLASH) { MemorySnapshot.MemoryBlock mb = new MemorySnapshot.MemoryBlock(); mb.m_address = m_snapshot.m_flashBase; size = ProbeMemory(mb.m_address, (int)m_snapshot.m_flashSize, 1024 * 1024); mb.m_data = new byte[size]; if (GetMemory(mb.m_address, mb.m_data, 0, size, "Loading FLASH") != size) { // ?? } m_snapshot.m_block_FLASH = mb; } else { m_snapshot.m_block_FLASH = null; } try { using (FileStream s = new FileStream(m_snapshot_File, FileMode.Create, FileAccess.Write)) { if (m_snapshot_Kind == 1) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter fmt = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); fmt.Serialize(s, m_snapshot); } else { BinaryWriter writer = new BinaryWriter(s); writer.Write((uint)0xDEADBEEF); if (m_snapshot_RAM) { MemorySnapshot.MemoryBlock mb = m_snapshot.m_block_RAM; writer.Write(mb.m_address); writer.Write((uint)mb.m_data.Length); writer.Write(mb.m_data, 0, mb.m_data.Length); } if (m_snapshot_FLASH) { MemorySnapshot.MemoryBlock mb = m_snapshot.m_block_FLASH; writer.Write(mb.m_address); writer.Write((uint)mb.m_data.Length); writer.Write(mb.m_data, 0, mb.m_data.Length); } writer.Flush(); } s.Flush(); } } catch { } } finally { try { Disconnect(); } catch { } m_worker = null; labelStatus.Text = ""; progressBarDownload.Value = 0; SetControlsStatus(true); } }