diff options
author | Mikayla Hutchinson <m.j.hutchinson@gmail.com> | 2018-06-15 03:48:20 +0300 |
---|---|---|
committer | Mikayla Hutchinson <m.j.hutchinson@gmail.com> | 2018-06-15 03:48:20 +0300 |
commit | e1673a8233647861b8c3e725ad710a48a65d8be8 (patch) | |
tree | 7e76fbe2b497884bf341b9177b9c230596e23f14 /main/src/addins/MonoDevelop.Debugger.Gdb | |
parent | ee98651d152923d6b527081d9e198fca9dc5bf8c (diff) |
[Gdb] Fix warnings
Diffstat (limited to 'main/src/addins/MonoDevelop.Debugger.Gdb')
3 files changed, 71 insertions, 44 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger.Gdb/GdbBacktrace.cs b/main/src/addins/MonoDevelop.Debugger.Gdb/GdbBacktrace.cs index 7aec2df3d0..5f9cf86b3e 100644 --- a/main/src/addins/MonoDevelop.Debugger.Gdb/GdbBacktrace.cs +++ b/main/src/addins/MonoDevelop.Debugger.Gdb/GdbBacktrace.cs @@ -331,7 +331,7 @@ namespace MonoDevelop.Debugger.Gdb sfile = frameData.GetValue ("file"); if (sfile == null) sfile = frameData.GetValue ("from"); - SourceLocation loc = new SourceLocation (func ?? "?", sfile, line); + var loc = new SourceLocation (func ?? "?", sfile, line, -1, -1, -1, null); long addr; if (!string.IsNullOrEmpty (sadr)) diff --git a/main/src/addins/MonoDevelop.Debugger.Gdb/GdbSessionFactory.cs b/main/src/addins/MonoDevelop.Debugger.Gdb/GdbSessionFactory.cs index a4e11b6877..2dec4e73c5 100644 --- a/main/src/addins/MonoDevelop.Debugger.Gdb/GdbSessionFactory.cs +++ b/main/src/addins/MonoDevelop.Debugger.Gdb/GdbSessionFactory.cs @@ -29,27 +29,26 @@ using System; using System.Collections.Generic; using System.IO; using Mono.Debugging.Client; -using Mono.Debugging.Backend; using MonoDevelop.Core.Execution; namespace MonoDevelop.Debugger.Gdb { - public class GdbSessionFactory: IDebuggerEngine + class GdbDebuggerBackend : DebuggerEngineBackend { - struct FileData { + struct FileData + { public DateTime LastCheck; public bool IsExe; } - - Dictionary<string,FileData> fileCheckCache = new Dictionary<string, FileData> (); - - public bool CanDebugCommand (ExecutionCommand command) + + Dictionary<string, FileData> fileCheckCache = new Dictionary<string, FileData> (); + + public override bool CanDebugCommand (ExecutionCommand cmd) { - NativeExecutionCommand cmd = command as NativeExecutionCommand; - if (cmd == null) + if (!(cmd is NativeExecutionCommand nativeCmd)) return false; - - string file = FindFile (cmd.Command); + + string file = FindFile (nativeCmd.Command); if (!File.Exists (file)) { // The provided file is not guaranteed to exist. If it doesn't // we assume we can execute it because otherwise the run command @@ -57,12 +56,11 @@ namespace MonoDevelop.Debugger.Gdb // command will build the project if the exec doesn't yet exist. return true; } - + file = Path.GetFullPath (file); DateTime currentTime = File.GetLastWriteTime (file); - - FileData data; - if (fileCheckCache.TryGetValue (file, out data)) { + + if (fileCheckCache.TryGetValue (file, out var data)) { if (data.LastCheck == currentTime) return data.IsExe; } @@ -75,28 +73,29 @@ namespace MonoDevelop.Debugger.Gdb fileCheckCache [file] = data; return data.IsExe; } - - public DebuggerStartInfo CreateDebuggerStartInfo (ExecutionCommand command) + + public override DebuggerStartInfo CreateDebuggerStartInfo (ExecutionCommand cmd) { - NativeExecutionCommand pec = (NativeExecutionCommand) command; - DebuggerStartInfo startInfo = new DebuggerStartInfo (); - startInfo.Command = pec.Command; - startInfo.Arguments = pec.Arguments; - startInfo.WorkingDirectory = pec.WorkingDirectory; - if (pec.EnvironmentVariables.Count > 0) { - foreach (KeyValuePair<string,string> val in pec.EnvironmentVariables) + var nativeCmd = (NativeExecutionCommand)cmd; + var startInfo = new DebuggerStartInfo { + Command = nativeCmd.Command, + Arguments = nativeCmd.Arguments, + WorkingDirectory = nativeCmd.WorkingDirectory + }; + if (nativeCmd.EnvironmentVariables.Count > 0) { + foreach (KeyValuePair<string, string> val in nativeCmd.EnvironmentVariables) startInfo.EnvironmentVariables [val.Key] = val.Value; } return startInfo; } - - public bool IsExecutable (string file) + + internal static bool IsExecutable (string file) { // HACK: this is a quick but not very reliable way of checking if a file // is a native executable. Actually, we are interested in checking that // the file is not a script. - using (StreamReader sr = new StreamReader (file)) { - char[] chars = new char[3]; + using (var sr = new StreamReader (file)) { + char [] chars = new char [3]; int n = 0, nr = 0; while (n < chars.Length && (nr = sr.ReadBlock (chars, n, chars.Length - n)) != 0) n += nr; @@ -108,18 +107,16 @@ namespace MonoDevelop.Debugger.Gdb return true; } - public DebuggerSession CreateSession () + public override DebuggerSession CreateSession () { - GdbSession ds = new GdbSession (); - return ds; + return new GdbSession (); } - - public ProcessInfo[] GetAttachableProcesses () + + public override ProcessInfo [] GetAttachableProcesses () { - List<ProcessInfo> procs = new List<ProcessInfo> (); + var procs = new List<ProcessInfo> (); foreach (string dir in Directory.GetDirectories ("/proc")) { - int id; - if (!int.TryParse (Path.GetFileName (dir), out id)) + if (!int.TryParse (Path.GetFileName (dir), out var id)) continue; try { File.ReadAllText (Path.Combine (dir, "sessionid")); @@ -127,19 +124,18 @@ namespace MonoDevelop.Debugger.Gdb continue; } string cmdline = File.ReadAllText (Path.Combine (dir, "cmdline")); - cmdline = cmdline.Replace ('\0',' '); - ProcessInfo pi = new ProcessInfo (id, cmdline); - procs.Add (pi); + cmdline = cmdline.Replace ('\0', ' '); + procs.Add (new ProcessInfo (id, cmdline)); } return procs.ToArray (); } - - string FindFile (string cmd) + + static string FindFile (string cmd) { if (Path.IsPathRooted (cmd)) return cmd; string pathVar = Environment.GetEnvironmentVariable ("PATH"); - string[] paths = pathVar.Split (Path.PathSeparator); + string [] paths = pathVar.Split (Path.PathSeparator); foreach (string path in paths) { string file = Path.Combine (path, cmd); if (File.Exists (file)) @@ -148,4 +144,35 @@ namespace MonoDevelop.Debugger.Gdb return cmd; } } + + [Obsolete ("Should not have been public")] + public class GdbSessionFactory: IDebuggerEngine + { + readonly GdbDebuggerBackend backend = new GdbDebuggerBackend (); + + public bool CanDebugCommand (ExecutionCommand command) + { + return backend.CanDebugCommand (command); + } + + public DebuggerStartInfo CreateDebuggerStartInfo (ExecutionCommand command) + { + return backend.CreateDebuggerStartInfo (command); + } + + public bool IsExecutable (string file) + { + return GdbDebuggerBackend.IsExecutable (file); + } + + public DebuggerSession CreateSession () + { + return backend.CreateSession (); + } + + public ProcessInfo[] GetAttachableProcesses () + { + return backend.GetAttachableProcesses (); + } + } } diff --git a/main/src/addins/MonoDevelop.Debugger.Gdb/Manifest.addin.xml b/main/src/addins/MonoDevelop.Debugger.Gdb/Manifest.addin.xml index 238f37937e..225c2cbde7 100644 --- a/main/src/addins/MonoDevelop.Debugger.Gdb/Manifest.addin.xml +++ b/main/src/addins/MonoDevelop.Debugger.Gdb/Manifest.addin.xml @@ -3,6 +3,6 @@ <DebuggerEngine id="Mono.Debugger.Gdb" name="GNU Debugger (GDB)" features="ConditionalBreakpoints, Tracepoints, Catchpoints, Attaching, DebugFile, Stepping, Pause, Breakpoints, Disassembly" - type="MonoDevelop.Debugger.Gdb.GdbSessionFactory" /> + type="MonoDevelop.Debugger.Gdb.GdbDebuggerBackend" /> </Extension> </ExtensionModel>
\ No newline at end of file |