Browse Source

Extended the loading of symbols for variables to also check the running directory.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/767/head
Dimitar Dobrev 10 years ago
parent
commit
b8df198d69
  1. 31
      src/Runtime/SymbolResolver.cs

31
src/Runtime/SymbolResolver.cs

@ -20,6 +20,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace CppSharp namespace CppSharp
@ -57,31 +60,27 @@ namespace CppSharp
public static IntPtr LoadImage (ref string name) public static IntPtr LoadImage (ref string name)
{ {
var pathvalues = Environment.GetEnvironmentVariable("PATH"); var pathValues = Environment.GetEnvironmentVariable("PATH");
var paths = new List<string>(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) foreach (var format in formats)
{ {
// Search the Current or specified directory for the library // Search the Current or specified directory for the library
string filename = string.Format(format, name); string filename = string.Format(format, name);
string attempted = System.IO.Path.Combine(Environment.CurrentDirectory, filename); string attempted = null;
if (!System.IO.File.Exists(attempted)) foreach (var path in paths)
{ {
// Search the Path directories for the library var fullPath = Path.Combine(path, filename);
if (pathvalues == null) if (File.Exists(fullPath))
continue;
foreach (var path in pathvalues.Split(System.IO.Path.PathSeparator))
{ {
var fullPath = System.IO.Path.Combine(path, filename); attempted = fullPath;
if (System.IO.File.Exists(fullPath)) break;
{
attempted = fullPath;
break;
}
} }
} }
if (!System.IO.File.Exists(attempted)) if (!File.Exists(attempted))
continue; continue;
var ptr = loadImage (attempted); var ptr = loadImage (attempted);

Loading…
Cancel
Save