Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

an error in main branch #17

Open
Luyoung0001 opened this issue Jun 10, 2024 · 0 comments
Open

an error in main branch #17

Luyoung0001 opened this issue Jun 10, 2024 · 0 comments

Comments

@Luyoung0001
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant