TartanLlama / minidbg

A mini x86 linux debugger for teaching purposes
MIT License
592 stars 104 forks source link

an error in main branch #17

Open Luyoung0001 opened 4 months ago

Luyoung0001 commented 4 months ago
void Debugger::print_backtrace() {
  auto output_frame = [frame_number = 0](auto &&func) mutable {
    std::cout << "frame #" << frame_number++ << ": 0x" << dwarf::at_low_pc(func)
              << ' ' << dwarf::at_name(func) << std::endl;
  };

  auto current_func = get_function_from_pc(get_offset_pc());
  output_frame(current_func);

  std::intptr_t frame_pointer = get_register_value(m_pid, registers::reg::rbp);
  std::intptr_t return_address = read_memory(frame_pointer + 8);

  while (dwarf::at_name(current_func) != "main") {
    current_func = get_function_from_pc(offset_load_address(return_address));
    output_frame(current_func);
    frame_pointer = read_memory(frame_pointer);
    return_address = read_memory(frame_pointer + 8);
  }
}

function should be fixed like this, when we want to get function by pc, the pc value must a an off-set one.Also, data type to describe an addr must be std::intptr_t in case of occurring bizarre problems.