internal void InitializeThreads(Inferior inferior) { TargetAddress ptr = inferior.ReadAddress(MonoDebuggerInfo.ThreadTable); while (!ptr.IsNull) { int size; if (MonoDebuggerInfo.CheckRuntimeVersion(81, 3)) { size = 60 + inferior.TargetMemoryInfo.TargetAddressSize; } else { size = 32 + inferior.TargetMemoryInfo.TargetAddressSize; } TargetReader reader = new TargetReader(inferior.ReadMemory(ptr, size)); long tid = reader.ReadLongInteger(); TargetAddress lmf_addr = reader.ReadAddress(); TargetAddress end_stack = reader.ReadAddress(); TargetAddress extended_notifications_addr = ptr + 24; if (inferior.TargetMemoryInfo.TargetAddressSize == 4) { tid &= 0x00000000ffffffffL; } reader.Offset += 8; ptr = reader.ReadAddress(); ThreadFlags flags = ThreadFlags.None; if (MonoDebuggerInfo.CheckRuntimeVersion(81, 3)) { reader.Offset = 56 + inferior.TargetAddressSize; flags = (ThreadFlags)reader.ReadInteger(); } bool found = false; foreach (SingleSteppingEngine engine in process.Engines) { if (engine.TID != tid) { continue; } engine.SetManagedThreadData(lmf_addr, extended_notifications_addr); engine.OnManagedThreadCreated(end_stack); check_thread_flags(engine, flags); found = true; break; } if (!found) { Report.Error("Cannot find thread {0:x} in {1}", tid, process.ProcessStart.CommandLine); } } }
void do_update_shlib_info(Inferior inferior) { // if (Process.MonoRuntimeFound) // return; if (!dyld_all_image_infos.IsNull) { int size = 2 * inferior.TargetLongIntegerSize + 2 * inferior.TargetAddressSize; TargetReader reader = new TargetReader(inferior.ReadMemory(dyld_all_image_infos, size)); reader.ReadLongInteger(); // version int infoArrayCount = (int)reader.ReadLongInteger(); TargetAddress infoArray = reader.ReadAddress(); size = infoArrayCount * (inferior.TargetLongIntegerSize + 2 * inferior.TargetAddressSize); reader = new TargetReader(inferior.ReadMemory(infoArray, size)); Console.Write("Loading symbols for shared libraries:"); for (int i = 0; i < infoArrayCount; i++) { TargetAddress imageLoadAddress = reader.ReadAddress(); TargetAddress imageFilePath = reader.ReadAddress(); reader.ReadLongInteger(); //imageFileModDate string name = inferior.ReadString(imageFilePath); if (name == null) { continue; } if (bfd_hash.Contains(name)) { continue; } try { Console.Write("."); AddExecutableFile(inferior, name, imageLoadAddress /*TargetAddress.Null*/, false, true); } catch (SymbolTableException e) { Console.WriteLine("Unable to load binary for " + name); bfd_hash.Add(name, null); } } Console.WriteLine(""); } }
void read_dynamic_info(Inferior inferior) { if (has_dynlink_info) { if (!first_link_map.IsNull) { do_update_shlib_info(inferior); } return; } TargetAddress debug_base = main_bfd.ReadDynamicInfo(inferior); if (debug_base.IsNull) { return; } int size = 2 * inferior.TargetLongIntegerSize + 3 * inferior.TargetAddressSize; TargetReader reader = new TargetReader(inferior.ReadMemory(debug_base, size)); if (reader.ReadLongInteger() != 1) { return; } first_link_map = reader.ReadAddress(); dynlink_breakpoint_addr = reader.ReadAddress(); rdebug_state_addr = debug_base + reader.Offset; if (reader.ReadLongInteger() != 0) { return; } has_dynlink_info = true; Instruction insn = inferior.Architecture.ReadInstruction(inferior, dynlink_breakpoint_addr); if ((insn == null) || !insn.CanInterpretInstruction) { throw new InternalError("Unknown dynlink breakpoint: {0}", dynlink_breakpoint_addr); } dynlink_breakpoint = new DynlinkBreakpoint(this, insn); dynlink_breakpoint.Insert(inferior); do_update_shlib_info(inferior); check_loaded_library(inferior, main_bfd); }
void do_update_shlib_info(Inferior inferior) { bool first = true; TargetAddress map = first_link_map; while (!map.IsNull) { int the_size = 4 * inferior.TargetAddressSize; TargetReader map_reader = new TargetReader(inferior.ReadMemory(map, the_size)); TargetAddress l_addr = map_reader.ReadAddress(); TargetAddress l_name = map_reader.ReadAddress(); map_reader.ReadAddress(); string name; try { name = inferior.ReadString(l_name); // glibc 2.3.x uses the empty string for the virtual // "linux-gate.so.1". if ((name != null) && (name == "")) { name = null; } } catch { name = null; } map = map_reader.ReadAddress(); if (first) { first = false; continue; } if (name == null) { continue; } if (bfd_hash.Contains(name)) { continue; } bool step_into = Process.ProcessStart.LoadNativeSymbolTable; AddExecutableFile(inferior, name, l_addr, step_into, true); } }
void read_dynamic_info(Inferior inferior) { if (has_dynlink_info) { if (!dyld_all_image_infos.IsNull) { do_update_shlib_info(inferior); } return; } TargetMemoryInfo info = Inferior.GetTargetMemoryInfo(AddressDomain.Global); Bfd dyld_image = new Bfd(this, info, "/usr/lib/dyld", TargetAddress.Null, true); dyld_all_image_infos = dyld_image.LookupSymbol("dyld_all_image_infos"); if (dyld_all_image_infos.IsNull) { return; } int size = 2 * inferior.TargetLongIntegerSize + 2 * inferior.TargetAddressSize; TargetReader reader = new TargetReader(inferior.ReadMemory(dyld_all_image_infos, size)); reader.ReadLongInteger(); // version reader.ReadLongInteger(); // infoArrayCount reader.ReadAddress(); // infoArray TargetAddress dyld_image_notifier = reader.ReadAddress(); has_dynlink_info = true; Instruction insn = inferior.Architecture.ReadInstruction(inferior, dyld_image_notifier); if ((insn == null) || !insn.CanInterpretInstruction) { throw new InternalError("Unknown dynlink breakpoint: {0}", dyld_image_notifier); } dynlink_breakpoint = new DynlinkBreakpoint(this, insn); dynlink_breakpoint.Insert(inferior); do_update_shlib_info(inferior); check_loaded_library(inferior, main_bfd); }
internal void InitializeThreads(Inferior inferior) { TargetAddress ptr = inferior.ReadAddress (MonoDebuggerInfo.ThreadTable); while (!ptr.IsNull) { int size; if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3)) size = 60 + inferior.TargetMemoryInfo.TargetAddressSize; else size = 32 + inferior.TargetMemoryInfo.TargetAddressSize; TargetReader reader = new TargetReader (inferior.ReadMemory (ptr, size)); long tid = reader.ReadLongInteger (); TargetAddress lmf_addr = reader.ReadAddress (); TargetAddress end_stack = reader.ReadAddress (); TargetAddress extended_notifications_addr = ptr + 24; if (inferior.TargetMemoryInfo.TargetAddressSize == 4) tid &= 0x00000000ffffffffL; reader.Offset += 8; ptr = reader.ReadAddress (); ThreadFlags flags = ThreadFlags.None; if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3)) { reader.Offset = 56 + inferior.TargetAddressSize; flags = (ThreadFlags) reader.ReadInteger (); } bool found = false; foreach (SingleSteppingEngine engine in process.Engines) { if (engine.TID != tid) continue; engine.SetManagedThreadData (lmf_addr, extended_notifications_addr); engine.OnManagedThreadCreated (end_stack); check_thread_flags (engine, flags); found = true; break; } if (!found) Report.Error ("Cannot find thread {0:x} in {1}", tid, process.ProcessStart.CommandLine); } }