mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 20:39:01 +00:00
98 lines
3.6 KiB
C#
98 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Cosmos.Debug.GDB {
|
|
public partial class FormDisassembly : Form {
|
|
protected class AsmLine {
|
|
public readonly UInt32 mAddr;
|
|
public readonly string mLabel;
|
|
public readonly string mOp;
|
|
public readonly string mData = "";
|
|
|
|
public AsmLine(string aInput) {
|
|
//"0x0056d2b9 <_end_data+0>:\tmov DWORD PTR ds:0x550020,ebx\n"
|
|
var s = GDB.Unescape(aInput);
|
|
var xSplit1 = s.Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
var xSplit2 = xSplit1[0].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
mAddr = Global.FromHex(xSplit2[0]);
|
|
string xLabel;
|
|
if (xSplit2.Length > 1) {
|
|
xLabel = xSplit2[1];
|
|
}
|
|
|
|
xSplit2 = xSplit1[1].Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
mOp = xSplit2[0];
|
|
if (xSplit2.Length > 1) {
|
|
for (int j = 1; j < xSplit2.Length; j++) {
|
|
mData += xSplit2[j] + " ";
|
|
}
|
|
mData = mData.TrimEnd();
|
|
}
|
|
}
|
|
|
|
public override string ToString() {
|
|
// First char reserved for breakpoint (*)
|
|
return " " + (mAddr.ToString("X8") + ": " + mOp + " " + mData).TrimEnd();
|
|
}
|
|
}
|
|
|
|
protected string mFuncName;
|
|
|
|
public FormDisassembly() {
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetEIP(UInt32 aAddr) {
|
|
foreach (AsmLine x in lboxDisassemble.Items) {
|
|
if (x.mAddr == aAddr) {
|
|
lboxDisassemble.SelectedItem = x;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void FormDisassembly_FormClosing(object sender, FormClosingEventArgs e) {
|
|
e.Cancel = true;
|
|
Hide();
|
|
}
|
|
|
|
private void mitemDisassemblyAddBreakpoint_Click(object sender, EventArgs e) {
|
|
var x = (AsmLine)lboxDisassemble.SelectedItem;
|
|
if (x != null) {
|
|
Windows.mBreakpointsForm.AddBreakpoint("*0x" + x.mAddr.ToString("X8"));
|
|
}
|
|
}
|
|
|
|
public void Disassemble(string aLabel) {
|
|
lablCurrentFunction.Text = "";
|
|
lablCurrentFunction.Visible = true;
|
|
|
|
var xResult = GDB.SendCmd(("disassemble " + aLabel).Trim()).Text;
|
|
lboxDisassemble.BeginUpdate();
|
|
try {
|
|
lboxDisassemble.Items.Clear();
|
|
// In some cases GDB might return no results. This is common when no symbols are loaded.
|
|
if (xResult.Count > 0) {
|
|
var xSplit = GDB.Unescape(xResult[1]).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|
mFuncName = xSplit[xSplit.Length - 1];
|
|
lablCurrentFunction.Text = mFuncName;
|
|
|
|
// 1 and -2 to eliminate header and footer line
|
|
for (int i = 1; i <= xResult.Count - 2; i++) {
|
|
lboxDisassemble.Items.Add(new AsmLine(xResult[i]));
|
|
}
|
|
}
|
|
} finally {
|
|
lboxDisassemble.EndUpdate();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|