Skip to content

Commit b8df198

Browse files
committed
Extended the loading of symbols for variables to also check the running directory.
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
1 parent dad52a2 commit b8df198

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/Runtime/SymbolResolver.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2121

2222
using System;
23+
using System.Collections.Generic;
24+
using System.IO;
25+
using System.Reflection;
2326
using System.Runtime.InteropServices;
2427

2528
namespace CppSharp
@@ -57,31 +60,27 @@ static SymbolResolver ()
5760

5861
public static IntPtr LoadImage (ref string name)
5962
{
60-
var pathvalues = Environment.GetEnvironmentVariable("PATH");
63+
var pathValues = Environment.GetEnvironmentVariable("PATH");
64+
var paths = new List<string>(pathValues == null ? new string[0] :
65+
pathValues.Split(Path.PathSeparator));
66+
paths.Insert(0, Directory.GetCurrentDirectory());
67+
paths.Insert(0, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
6168

6269
foreach (var format in formats)
6370
{
6471
// Search the Current or specified directory for the library
6572
string filename = string.Format(format, name);
66-
string attempted = System.IO.Path.Combine(Environment.CurrentDirectory, filename);
67-
if (!System.IO.File.Exists(attempted))
73+
string attempted = null;
74+
foreach (var path in paths)
6875
{
69-
// Search the Path directories for the library
70-
if (pathvalues == null)
71-
continue;
72-
73-
foreach (var path in pathvalues.Split(System.IO.Path.PathSeparator))
76+
var fullPath = Path.Combine(path, filename);
77+
if (File.Exists(fullPath))
7478
{
75-
var fullPath = System.IO.Path.Combine(path, filename);
76-
if (System.IO.File.Exists(fullPath))
77-
{
78-
attempted = fullPath;
79-
break;
80-
}
81-
79+
attempted = fullPath;
80+
break;
8281
}
8382
}
84-
if (!System.IO.File.Exists(attempted))
83+
if (!File.Exists(attempted))
8584
continue;
8685

8786
var ptr = loadImage (attempted);

0 commit comments

Comments
 (0)