JD2022-TU1/main/tools/legacy/MemoryViewer/CallstackViewer.cs

63 lines
2.1 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;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace MemoryViewer
{
public partial class CallstackViewer : Form
{
public CallstackViewer()
{
InitializeComponent();
}
private void callStackText_MouseDoubleClick(object sender, MouseEventArgs e)
{
string[] lines = Regex.Split(callStackText.SelectedText, "\r\n");
if (lines != null && lines.Length > 0)
{
string selectedLine = lines[0];
//open ms with specific file name and line
int index = selectedLine.LastIndexOf("(");
string filename = "";
if (index != -1)
{
filename = selectedLine.Substring(0, index);
int indexline = selectedLine.IndexOf(')');
if (indexline != -1)
{
int filePathStartIndex = 0;
char prevChar = '!';
for (int i = callStackText.SelectionStart; i > 0; --i)
{
char curChar = callStackText.Text[i];
if (prevChar == '\\' && curChar == ':')
{
filePathStartIndex = i - 1;
break;
}
prevChar = curChar;
}
if(filePathStartIndex != 0)
filename = callStackText.Text.Substring(filePathStartIndex, callStackText.SelectionStart - filePathStartIndex);
string line = selectedLine.Substring(index + 1, indexline - index - 1);
MemoryUtils.openFileAtLine(filename, line);
}
}
}
}
}
}