From b8df198d69ef2d53fd595f3f86c68ed70534b3a5 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 18 Feb 2017 00:16:37 +0200 Subject: [PATCH] Extended the loading of symbols for variables to also check the running directory. Signed-off-by: Dimitar Dobrev --- src/Runtime/SymbolResolver.cs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Runtime/SymbolResolver.cs b/src/Runtime/SymbolResolver.cs index 024e9eb3..28e0e745 100644 --- a/src/Runtime/SymbolResolver.cs +++ b/src/Runtime/SymbolResolver.cs @@ -20,6 +20,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; using System.Runtime.InteropServices; namespace CppSharp @@ -57,31 +60,27 @@ namespace CppSharp public static IntPtr LoadImage (ref string name) { - var pathvalues = Environment.GetEnvironmentVariable("PATH"); + var pathValues = Environment.GetEnvironmentVariable("PATH"); + var paths = new List(pathValues == null ? new string[0] : + pathValues.Split(Path.PathSeparator)); + paths.Insert(0, Directory.GetCurrentDirectory()); + paths.Insert(0, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); foreach (var format in formats) { // Search the Current or specified directory for the library string filename = string.Format(format, name); - string attempted = System.IO.Path.Combine(Environment.CurrentDirectory, filename); - if (!System.IO.File.Exists(attempted)) + string attempted = null; + foreach (var path in paths) { - // Search the Path directories for the library - if (pathvalues == null) - continue; - - foreach (var path in pathvalues.Split(System.IO.Path.PathSeparator)) + var fullPath = Path.Combine(path, filename); + if (File.Exists(fullPath)) { - var fullPath = System.IO.Path.Combine(path, filename); - if (System.IO.File.Exists(fullPath)) - { - attempted = fullPath; - break; - } - + attempted = fullPath; + break; } } - if (!System.IO.File.Exists(attempted)) + if (!File.Exists(attempted)) continue; var ptr = loadImage (attempted);