调试Bochs在Linux Mint下面symbol not found的问题
在我的Linux Mint上使用Bochs时出现了很奇怪的问题,按照http://www.cnblogs.com/long123king/p/3568575.html步骤
会提示:
1 | symbol not found |
因此,我决定使用gdb调试Bochs找出究竟发生了什么奇怪的问题。
1. 如何配置.conf.linux
添加-g -O0到CFLAGS/CXXFLAGS
2. 重新生成bochs程序
1 | sudo make bochs |
3. 参考:http://code.google.com/p/stl-debug/
添加对STL容器的调试支持
调试:
1 | sudo gdb --args ~/latest_bochs/bochs/bochs -q -f bxrc_custom -rc script_debug_custom |
4. 添加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | symbol_entry_t* context_t::get_symbol_entry( const char *symbol) const { if (m_rsyms.empty()) return 0; symbol_entry_t probe(0, symbol); rsym_set_t::const_iterator iter; for (std:: set <symbol_entry_t*, lt_rsymbol_entry_t>::iterator it = m_rsyms.begin(); it != m_rsyms.end(); it++) { unsigned long start = (*it)->start; char * name = (*it)->name; if (strncmp(name, "start_kernel" , strlen( "start_kernel" )) == 0) { int kkk = 0; } dbg_printf( "0x%08X : %s\n" , start, name); continue ; } iter=m_rsyms.find(&probe); if (iter==m_rsyms.end()) // No symbol found return 0; return *iter; } ++sym_name;<br><br> char *ending = (sym_name + strlen(sym_name) - 1);<br> while ( isspace(*ending) && ending != sym_name)<br>{<br> *(ending--) = '\0' ;<br>}<br><br> symbol_entry_t* sym = new symbol_entry_t(addr + offset, sym_name);<br><br> |
在int kkk=0;这一行设置断点,发现:
1 2 3 4 5 6 7 8 9 | Breakpoint 1, context_t::get_symbol_entry ( this =0x2860cf0, symbol=0x2860cd0 "start_kernel" ) at symbols.cc:213 213 int kkk = 0; (gdb) info locals kkk = 0 start = 3246113809 name = 0x3155e30 "start_kernel\r" it = {_M_node = 0x3155e80} probe = {name = 0x2536e70 "start_kernel" , start = 0} iter = {_M_node = 0x0} |
怎么会多了一个"\r"呢,相信这就是问题的所在。
在add_symbol处设置断点,重新调试
1 2 3 4 5 6 7 | Breakpoint 2, context_t::add_symbol ( this =0x2860cf0, sym=0x2860fa0) at symbols.cc:226 226 m_syms.insert(sym); (gdb) print sym.start $1 = 0 (gdb) print sym.name $2 = 0x2860fc0 "VDSO32_PRELINK\r" (gdb) |
确认问题。
解决方法:
在bx_dbg_symbol_command函数中添加如下代码:
1 2 3 4 5 6 7 8 9 | ++sym_name; char *ending = (sym_name + strlen(sym_name) - 1); while ( isspace(*ending) && ending != sym_name) { *(ending--) = '\0' ; } symbol_entry_t* sym = new symbol_entry_t(addr + offset, sym_name); |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)