| 32 | } |
| 33 | |
| 34 | auto DumpStack() -> void { |
| 35 | std::array<uint64_t, kMaxFrameCount> buffer{}; |
| 36 | |
| 37 | // 获取调用栈中的地址 |
| 38 | auto num_frames = backtrace(buffer); |
| 39 | |
| 40 | // 打印函数名 |
| 41 | for (auto current_frame_idx = 0; current_frame_idx < num_frames; |
| 42 | current_frame_idx++) { |
| 43 | for (auto symtab : KernelElfSingleton::instance().symtab) { |
| 44 | if ((ELF64_ST_TYPE(symtab.st_info) == STT_FUNC) && |
| 45 | (buffer[current_frame_idx] >= symtab.st_value) && |
| 46 | (buffer[current_frame_idx] <= symtab.st_value + symtab.st_size)) { |
| 47 | klog::Err("[{}] {:#x}", |
| 48 | reinterpret_cast<const char*>( |
| 49 | KernelElfSingleton::instance().strtab + symtab.st_name), |
| 50 | buffer[current_frame_idx]); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | } |