Skip to content

Commit cf80c0d

Browse files
committed
Added a basic Renesas toolchain importer and a debug package
1 parent d164d98 commit cf80c0d

26 files changed

+1788
-4
lines changed

DebugPackages/ESP8266DebugPackage/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
[assembly: AssemblyCulture("")]
1717
[assembly: ComVisible(false)]
1818

19-
[assembly: AssemblyVersion("2.0.1569.0")]
20-
[assembly: AssemblyFileVersion("2.0.1569.0")]
19+
[assembly: AssemblyVersion("2.0.1600.0")]
20+
[assembly: AssemblyFileVersion("2.0.1600.0")]

DebugPackages/RISCVDebugPackage/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.1158.0")]
36-
[assembly: AssemblyFileVersion("1.0.1158.0")]
35+
[assembly: AssemblyVersion("1.0.1179.0")]
36+
[assembly: AssemblyFileVersion("1.0.1179.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<UserControl x:Class="RenesasDebugPackage.GUI.RenesasDebugSettingsControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:RenesasDebugPackage.GUI"
7+
mc:Ignorable="d"
8+
d:DesignHeight="450" d:DesignWidth="800">
9+
<Grid>
10+
<Grid.Resources>
11+
<local:MaxWidthConverter x:Key="MaxWidthConverter"/>
12+
</Grid.Resources>
13+
<Expander Grid.ColumnSpan="2" MinHeight="64" Grid.Row="14" Header="Advanced settings" IsExpanded="False">
14+
<Grid MinHeight="80" Margin="20 0 5 5">
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="Auto"/>
17+
<RowDefinition Height="*" MinHeight="80"/>
18+
</Grid.RowDefinitions>
19+
<Grid.ColumnDefinitions>
20+
<ColumnDefinition Width="*"/>
21+
<!--<ColumnDefinition Width="*"/>-->
22+
</Grid.ColumnDefinitions>
23+
24+
<TextBlock Text="Command line:" Margin="2"/>
25+
<TextBox Margin="2" Text="{Binding CommandLine, UpdateSourceTrigger=LostFocus}" Grid.Column="0" Grid.Row="1"
26+
AcceptsReturn="False" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch"
27+
MaxWidth="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:RenesasDebugSettingsControl}}, Converter={StaticResource MaxWidthConverter}}"/>
28+
<!--
29+
<TextBlock Text="Startup GDB commands:" Margin="2" Grid.Column="1"/>
30+
<TextBox Margin="2" Grid.Column="1" Text="{Binding StartupCommands, UpdateSourceTrigger=LostFocus}" Grid.Row="1" AcceptsReturn="True"
31+
TextWrapping="NoWrap" VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Auto"/>-->
32+
</Grid>
33+
</Expander>
34+
35+
</Grid>
36+
</UserControl>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using BSPEngine;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Globalization;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace RenesasDebugPackage.GUI
19+
{
20+
/// <summary>
21+
/// Interaction logic for RenesasDebugSettingsControl.xaml
22+
/// </summary>
23+
public partial class RenesasDebugSettingsControl : UserControl
24+
{
25+
public RenesasDebugSettingsControl(LoadedBSP.LoadedDebugMethod method, IBSPConfiguratorHost host, RenesasDebugController controller)
26+
{
27+
InitializeComponent();
28+
DataContext = Controller = new ControllerImpl(this, method, host, controller);
29+
}
30+
31+
public ControllerImpl Controller { get; }
32+
33+
public class ControllerImpl : ICustomDebugMethodConfigurator, INotifyPropertyChanged
34+
{
35+
void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
36+
37+
RenesasGDBServerCommandLine _CommandLine;
38+
39+
public ControllerImpl(RenesasDebugSettingsControl control, LoadedBSP.LoadedDebugMethod method, IBSPConfiguratorHost host, RenesasDebugController controller)
40+
{
41+
Control = control;
42+
TypeProvider = controller;
43+
_CommandLine = new RenesasGDBServerCommandLine(new RenesasDebugSettings().CommandLineArguments);
44+
}
45+
46+
public string CommandLine
47+
{
48+
get => _CommandLine.CommandLine;
49+
set
50+
{
51+
_CommandLine.CommandLine = value;
52+
OnCommandLineChanged();
53+
}
54+
}
55+
56+
void OnCommandLineChanged()
57+
{
58+
OnPropertyChanged(nameof(CommandLine));
59+
}
60+
61+
public object Control { get; }
62+
63+
public object Configuration => new RenesasDebugSettings { CommandLineArguments = _CommandLine.CommandLine };
64+
65+
public ICustomSettingsTypeProvider TypeProvider { get; }
66+
67+
public bool SupportsLiveVariables => false;
68+
69+
public event EventHandler SettingsChanged;
70+
public event PropertyChangedEventHandler PropertyChanged;
71+
72+
public void SetConfiguration(object configuration, KnownInterfaceInstance context)
73+
{
74+
_CommandLine = new RenesasGDBServerCommandLine(((configuration as RenesasDebugSettings) ?? new RenesasDebugSettings()).CommandLineArguments);
75+
}
76+
77+
public bool TryFixSettingsFromStubError(IGDBStubInstance stub)
78+
{
79+
return false;
80+
}
81+
82+
public string ValidateSettings()
83+
{
84+
return null;
85+
}
86+
}
87+
}
88+
89+
public class MaxWidthConverter : IValueConverter
90+
{
91+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
92+
{
93+
if (value is double)
94+
return (double)value * 1;
95+
else
96+
return value;
97+
}
98+
99+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
100+
{
101+
throw new NotImplementedException();
102+
}
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("RenesasDebugPackage")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("RenesasDebugPackage")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("e330f522-a7e4-450e-97e5-244f7e14e114")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
using BSPEngine;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading;
8+
9+
namespace RenesasDebugPackage
10+
{
11+
public class RenesasDebugController : IDebugMethodController, ICustomSettingsTypeProvider
12+
{
13+
public virtual Type[] SettingsObjectTypes => new[] { typeof(RenesasDebugSettings) };
14+
15+
public virtual ICustomSettingsTypeProvider TypeProvider => this;
16+
17+
public virtual bool SupportsConnectionTesting => false;
18+
19+
public virtual ICustomDebugMethodConfigurator CreateConfigurator(LoadedBSP.LoadedDebugMethod method, IBSPConfiguratorHost host)
20+
{
21+
return new GUI.RenesasDebugSettingsControl(method, host, this).Controller;
22+
}
23+
24+
public IGDBStubInstance StartGDBStub(IDebugStartService startService, DebugStartContext context)
25+
{
26+
var settings = (RenesasDebugSettings)context.Configuration ?? new RenesasDebugSettings();
27+
28+
var cmdLine = new RenesasGDBServerCommandLine(settings.CommandLineArguments);
29+
int gdbPort;
30+
using (var allocator = startService.BeginAllocatingTCPPorts())
31+
{
32+
cmdLine.GDBPort = gdbPort = allocator.AllocateUnusedTCPPort("SYS:GDB_PORT");
33+
cmdLine.AuxiliaryPort = allocator.AllocateUnusedTCPPort("com.sysprogs.renesas.auxiliary_port");
34+
}
35+
36+
string debugComponentLinkFile = Path.Combine(GetOpenOCDDirectory(context.Method.Directory), "DebugCompLink.txt");
37+
if (!File.Exists(debugComponentLinkFile))
38+
throw new Exception($"{debugComponentLinkFile} does not exist");
39+
40+
cmdLine.DeviceID = startService.MCU.ExpandedMCU.ID;
41+
if (cmdLine.DebugInterface == null)
42+
cmdLine.DebugInterface = "EZ";
43+
44+
string debugComponentDir = File.ReadAllText(debugComponentLinkFile);
45+
string e2gdbServer = Path.Combine(debugComponentDir, "e2-server-gdb.exe");
46+
if (!File.Exists(e2gdbServer))
47+
throw new Exception("Could not find " + e2gdbServer);
48+
49+
var tool = startService.LaunchCommandLineTool(new CommandLineToolLaunchInfo
50+
{
51+
Command = e2gdbServer,
52+
Arguments = cmdLine.CommandLine,
53+
WorkingDirectory = Path.GetDirectoryName(e2gdbServer)
54+
});
55+
56+
return new RenesasGDBStub(context, settings, cmdLine, gdbPort, tool);
57+
}
58+
59+
protected virtual string GetOpenOCDDirectory(string methodDir)
60+
{
61+
return methodDir;
62+
}
63+
64+
public virtual object TryConvertLegacyConfiguration(IBSPConfiguratorHost host, string methodDirectory, Dictionary<string, string> legacyConfiguration) => null;
65+
66+
class RenesasGDBStub : IGDBStubInstance
67+
{
68+
private readonly int _GDBPort;
69+
private readonly RenesasDebugSettings _Settings;
70+
private readonly RenesasGDBServerCommandLine _CmdLine;
71+
72+
public RenesasGDBStub(DebugStartContext context, RenesasDebugSettings settings, RenesasGDBServerCommandLine cmdLine, int gdbPort, IExternalToolInstance tool)
73+
{
74+
Tool = tool;
75+
_CmdLine = cmdLine;
76+
_GDBPort = gdbPort;
77+
_Settings = settings;
78+
}
79+
80+
public IExternalToolInstance Tool { get; private set; }
81+
82+
83+
public object LocalGDBEndpoint => _GDBPort;
84+
85+
public IConsoleOutputClassifier OutputClassifier => null;
86+
87+
public virtual void ConnectGDBToStub(IDebugStartService service, ISimpleGDBSession session)
88+
{
89+
string[] regularStartupCommands = new[]
90+
{
91+
"-gdb-set breakpoint pending on",
92+
"-gdb-set detach-on-fork on",
93+
"-gdb-set python print-stack none",
94+
"-gdb-set print object on",
95+
"-gdb-set print sevenbit-strings on",
96+
"-gdb-set host-charset UTF-8",
97+
"-gdb-set target-charset WINDOWS-1252",
98+
"-gdb-set target-wide-charset UTF-16",
99+
"-gdb-set pagination off",
100+
"-gdb-set auto-solib-add on",
101+
"inferior 1",
102+
"set remotetimeout 10",
103+
"set tcp connect-timeout 30",
104+
};
105+
106+
SimpleGDBCommandResult result;
107+
foreach(var cmd in regularStartupCommands)
108+
{
109+
result = session.RunGDBCommand(cmd);
110+
if (!result.IsDone)
111+
throw new Exception("GDB command failed: " + cmd);
112+
}
113+
114+
session.EnableAsyncMode(GDBAsyncMode.AsyncWithTemporaryBreaks, true, true);
115+
session.ConnectToExtendedRemote(null, _GDBPort, true);
116+
117+
result = session.RunGDBCommand("mon is_target_connected");
118+
if (!result.IsDone)
119+
throw new Exception("The target did not report connection state");
120+
121+
if (result.StubOutput?.FirstOrDefault(l=>l.Trim() == "Connection status=connected.") == null)
122+
throw new Exception("The Renesas gdb stub is not connected to the target.");
123+
124+
result = session.RunGDBCommand("monitor get_no_hw_bkpts_available");
125+
if (result.IsDone && result.StubOutput != null)
126+
foreach(var line in result.StubOutput)
127+
{
128+
if (int.TryParse(line.Trim(), out var tmp))
129+
{
130+
session.RunGDBCommand($"set remote hardware-breakpoint-limit " + tmp);
131+
break;
132+
}
133+
}
134+
135+
result = session.RunGDBCommand("monitor get_target_max_address");
136+
if (result.IsDone && result.StubOutput != null)
137+
foreach (var line in result.StubOutput)
138+
{
139+
string trimmedLine = line.Trim();
140+
if (trimmedLine.StartsWith("0x") && int.TryParse(trimmedLine.Substring(2), System.Globalization.NumberStyles.HexNumber, null, out var tmp))
141+
{
142+
session.RunGDBCommand($"mem 0x0 0x{tmp+1:x} rw 8 nocache");
143+
break;
144+
}
145+
}
146+
147+
result = session.RunGDBCommand("monitor configuration_complete");
148+
result = session.RunGDBCommand("monitor prg_download_start_on_connect");
149+
150+
result = session.RunGDBCommand("load");
151+
if (!result.IsDone)
152+
throw new Exception("Failed to program FLASH memory");
153+
154+
string[] finalCommands = new[]
155+
{
156+
"monitor prg_download_end",
157+
"monitor reset",
158+
"monitor enable_stopped_notify_on_connect",
159+
"monitor enable_execute_on_connect",
160+
};
161+
162+
using (var awaiter = session.InterceptFirstStoppedEvent())
163+
{
164+
foreach (var cmd in finalCommands)
165+
{
166+
result = session.RunGDBCommand(cmd);
167+
if (!result.IsDone)
168+
throw new Exception("GDB command failed: " + cmd);
169+
}
170+
171+
while (!awaiter.WaitForStop(100))
172+
session.RunGDBCommand("monitor do_nothing");
173+
}
174+
}
175+
176+
public ILiveMemoryEvaluator CreateLiveMemoryEvaluator(IDebugStartService service) => null;
177+
178+
public void Dispose()
179+
{
180+
}
181+
182+
public string TryGetMeaningfulErrorMessageFromStubOutput()
183+
{
184+
return null;
185+
}
186+
187+
public bool WaitForToolToStart(ManualResetEvent cancelEvent)
188+
{
189+
while (!cancelEvent.WaitOne(100))
190+
{
191+
if (!Tool.IsRunning || Tool.AllText.Contains("\nFinished target connection"))
192+
return true;
193+
}
194+
return true;
195+
}
196+
}
197+
}
198+
199+
}

0 commit comments

Comments
 (0)