internal static unsafe object[] DoUnwind(Unwinder u, UIntPtr exit_address, bool get_symbols = true) { System.Collections.ArrayList ret = new System.Collections.ArrayList(); UIntPtr pc; while (u.CanContinue() && ((pc = u.GetInstructionPointer()) != exit_address)) { void * offset; string sym; if (get_symbols) { sym = JitOperations.GetNameOfAddress((void *)pc, out offset); } else { offset = (void *)pc; sym = "offset_0"; } ret.Add(new UnwinderEntry { ProgramCounter = pc, Symbol = sym, Offset = (UIntPtr)offset }); u.UnwindOne(); } return(ret.ToArray()); }
static System.Reflection.Assembly GetExecutingAssembly() { // Return the System.Reflection.Assembly object of the code which called this function libsupcs.Unwinder u = Program.arch.GetUnwinder(); u.UnwindOne(); libsupcs.TysosMethod prev_method = u.GetMethodInfo(); if (prev_method == null || prev_method.DeclaringType == null) { /* We don't have enough information to determine the currently executing * method (and therefore assembly), so return mscorlib instead */ return(ReinterpretAsAssembly(mscorlib_assembly)); } return(prev_method.DeclaringType.Assembly); }
static void GetExecutingAssembly(StackCrawlMarkHandle scmh, TysosModule.ObjectHandleOnStack ret) { int scm = *(int *)scmh.ptr; System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: scm: " + scm.ToString()); Unwinder u = OtherOperations.GetUnwinder(); u.UnwindOne(); u.UnwindOne(); // we are double-nested within coreclr so unwind this and calling method (GetExecutingAssembly(ref StackMarkHandle)) first switch (scm) { case 0: break; case 1: u.UnwindOne(); break; case 2: u.UnwindOne(); u.UnwindOne(); break; default: System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: unsupported scm: " + scm.ToString()); throw new NotSupportedException(); } System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: requested pc " + ((ulong)u.GetInstructionPointer()).ToString("X")); void *offset; var name = JitOperations.GetNameOfAddress((void *)u.GetInstructionPointer(), out offset); if (name == null) { System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: symbol not found"); *ret.ptr = null; return; } System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: found method " + name); var ts = Metadata.MSCorlib.DemangleObject(name); if (ts == null) { System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: demangler returned null"); *ret.ptr = null; return; } var m = ts.Metadata; if (m == null) { System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: returned ts had no assembly"); *ret.ptr = null; return; } var aptr = (m.file as Metadata.BinaryInterface).b; var retm = TysosModule.GetModule(aptr, m.AssemblyName); System.Diagnostics.Debugger.Log(0, "libsupcs", "TysosAssembly.GetExecutingAssembly: returning " + retm.ass.assemblyName); *ret.ptr = CastOperations.ReinterpretAsPointer(retm.ass); }