Skip to content

Commit 6447054

Browse files
committed
Added unexpected error handlers around DIA symbol load functions
1 parent f9e2062 commit 6447054

File tree

2 files changed

+79
-43
lines changed

2 files changed

+79
-43
lines changed

LuaDkmDebuggerComponent/AttachmentHelpers.cs

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -291,64 +291,91 @@ internal static IDiaSymbol TryGetDiaFunctionSymbol(DkmNativeModuleInstance modul
291291

292292
internal static ulong? TryGetFunctionAddress(DkmNativeModuleInstance moduleInstance, string name, out string error)
293293
{
294-
var functionSymbol = TryGetDiaFunctionSymbol(moduleInstance, name, out error);
294+
try
295+
{
296+
var functionSymbol = TryGetDiaFunctionSymbol(moduleInstance, name, out error);
295297

296-
if (functionSymbol == null)
297-
return null;
298+
if (functionSymbol == null)
299+
return null;
298300

299-
uint rva = functionSymbol.relativeVirtualAddress;
301+
uint rva = functionSymbol.relativeVirtualAddress;
300302

301-
ReleaseComObject(functionSymbol);
303+
ReleaseComObject(functionSymbol);
302304

303-
return moduleInstance.BaseAddress + rva;
305+
return moduleInstance.BaseAddress + rva;
306+
}
307+
catch (Exception ex)
308+
{
309+
error = "TryGetFunctionAddress() Unexpected error: " + ex.ToString();
310+
}
311+
312+
return null;
304313
}
305314

306315
internal static ulong? TryGetFunctionAddressAtDebugStart(DkmNativeModuleInstance moduleInstance, string name, out string error)
307316
{
308-
var functionSymbol = TryGetDiaFunctionSymbol(moduleInstance, name, out error);
317+
try
318+
{
319+
var functionSymbol = TryGetDiaFunctionSymbol(moduleInstance, name, out error);
309320

310-
if (functionSymbol == null)
311-
return null;
321+
if (functionSymbol == null)
322+
return null;
312323

313-
var functionStartSymbol = TryGetDiaSymbol(functionSymbol, SymTagEnum.SymTagFuncDebugStart, null, out error);
324+
var functionStartSymbol = TryGetDiaSymbol(functionSymbol, SymTagEnum.SymTagFuncDebugStart, null, out error);
314325

315-
if (functionStartSymbol == null)
316-
{
317-
ReleaseComObject(functionSymbol);
326+
if (functionStartSymbol == null)
327+
{
328+
ReleaseComObject(functionSymbol);
318329

319-
return null;
320-
}
330+
return null;
331+
}
332+
333+
uint rva = functionStartSymbol.relativeVirtualAddress;
321334

322-
uint rva = functionStartSymbol.relativeVirtualAddress;
335+
ReleaseComObject(functionStartSymbol);
336+
ReleaseComObject(functionSymbol);
323337

324-
ReleaseComObject(functionStartSymbol);
325-
ReleaseComObject(functionSymbol);
338+
return moduleInstance.BaseAddress + rva;
339+
}
340+
catch (Exception ex)
341+
{
342+
error = "TryGetFunctionAddressAtDebugStart() Unexpected error: " + ex.ToString();
343+
}
326344

327-
return moduleInstance.BaseAddress + rva;
345+
return null;
328346
}
329347

330348
internal static ulong? TryGetFunctionAddressAtDebugEnd(DkmNativeModuleInstance moduleInstance, string name, out string error)
331349
{
332-
var functionSymbol = TryGetDiaFunctionSymbol(moduleInstance, name, out error);
350+
try
351+
{
352+
var functionSymbol = TryGetDiaFunctionSymbol(moduleInstance, name, out error);
333353

334-
if (functionSymbol == null)
335-
return null;
354+
if (functionSymbol == null)
355+
return null;
336356

337-
var functionEndSymbol = TryGetDiaSymbol(functionSymbol, SymTagEnum.SymTagFuncDebugEnd, null, out error);
357+
var functionEndSymbol = TryGetDiaSymbol(functionSymbol, SymTagEnum.SymTagFuncDebugEnd, null, out error);
338358

339-
if (functionEndSymbol == null)
340-
{
341-
ReleaseComObject(functionSymbol);
359+
if (functionEndSymbol == null)
360+
{
361+
ReleaseComObject(functionSymbol);
342362

343-
return null;
344-
}
363+
return null;
364+
}
365+
366+
uint rva = functionEndSymbol.relativeVirtualAddress;
345367

346-
uint rva = functionEndSymbol.relativeVirtualAddress;
368+
ReleaseComObject(functionEndSymbol);
369+
ReleaseComObject(functionSymbol);
347370

348-
ReleaseComObject(functionEndSymbol);
349-
ReleaseComObject(functionSymbol);
371+
return moduleInstance.BaseAddress + rva;
372+
}
373+
catch (Exception ex)
374+
{
375+
error = "TryGetFunctionAddressAtDebugEnd() Unexpected error: " + ex.ToString();
376+
}
350377

351-
return moduleInstance.BaseAddress + rva;
378+
return null;
352379
}
353380

354381
internal static Guid? CreateHelperFunctionBreakpoint(DkmNativeModuleInstance nativeModuleInstance, string functionName)

LuaDkmDebuggerComponent/LocalComponent.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,9 +2338,9 @@ void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance m
23382338

23392339
UpdateEvaluationHelperWorkerConnection(process);
23402340
}
2341-
catch (Exception)
2341+
catch (Exception ex)
23422342
{
2343-
log.Debug("Local symbols connection is not available");
2343+
log.Debug("Local symbols connection is not available: " + ex.ToString());
23442344
}
23452345

23462346
if (luaLocations != null)
@@ -2358,18 +2358,27 @@ void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance m
23582358
processData.executionStartAddress = processData.luaLocations.luaExecuteAtStart;
23592359
processData.executionEndAddress = processData.luaLocations.luaExecuteAtEnd;
23602360
}
2361-
else if (AttachmentHelpers.TryGetFunctionAddress(nativeModuleInstance, "lua_newstate", out _).GetValueOrDefault(0) != 0 || AttachmentHelpers.TryGetFunctionAddress(nativeModuleInstance, "luaL_newstate", out _).GetValueOrDefault(0) != 0)
2361+
else
23622362
{
2363-
log.Debug("Found Lua library (from an IDE component)");
2363+
if (AttachmentHelpers.TryGetFunctionAddress(nativeModuleInstance, "lua_newstate", out string errorA).GetValueOrDefault(0) != 0 || AttachmentHelpers.TryGetFunctionAddress(nativeModuleInstance, "luaL_newstate", out string errorB).GetValueOrDefault(0) != 0)
2364+
{
2365+
log.Debug("Found Lua library (from an IDE component)");
23642366

2365-
processData.moduleWithLoadedLua = nativeModuleInstance;
2367+
processData.moduleWithLoadedLua = nativeModuleInstance;
23662368

2367-
processData.executionStartAddress = AttachmentHelpers.TryGetFunctionAddressAtDebugStart(processData.moduleWithLoadedLua, "luaV_execute", out _).GetValueOrDefault(0);
2368-
processData.executionEndAddress = AttachmentHelpers.TryGetFunctionAddressAtDebugEnd(processData.moduleWithLoadedLua, "luaV_execute", out _).GetValueOrDefault(0);
2369-
}
2370-
else
2371-
{
2372-
log.Warning("Failed to find Lua library");
2369+
processData.executionStartAddress = AttachmentHelpers.TryGetFunctionAddressAtDebugStart(processData.moduleWithLoadedLua, "luaV_execute", out _).GetValueOrDefault(0);
2370+
processData.executionEndAddress = AttachmentHelpers.TryGetFunctionAddressAtDebugEnd(processData.moduleWithLoadedLua, "luaV_execute", out _).GetValueOrDefault(0);
2371+
}
2372+
else
2373+
{
2374+
if (errorA != null && errorA.Length != 0)
2375+
log.Error("Failed to find lua_newstate with: " + errorA);
2376+
2377+
if (errorB != null && errorB.Length != 0)
2378+
log.Error("Failed to find luaL_newstate with: " + errorB);
2379+
2380+
log.Warning("Failed to find Lua library");
2381+
}
23732382
}
23742383
}
23752384

0 commit comments

Comments
 (0)