调试Bochs在Linux Mint下面symbol not found的问题
在我的Linux Mint上使用Bochs时出现了很奇怪的问题,按照http://www.cnblogs.com/long123king/p/3568575.html步骤
会提示:
symbol not found
因此,我决定使用gdb调试Bochs找出究竟发生了什么奇怪的问题。
1. 如何配置.conf.linux
添加-g -O0到CFLAGS/CXXFLAGS
2. 重新生成bochs程序
sudo make bochs
3. 参考:http://code.google.com/p/stl-debug/
添加对STL容器的调试支持
调试:
sudo gdb --args ~/latest_bochs/bochs/bochs -q -f bxrc_custom -rc script_debug_custom
4. 添加如下代码:
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;
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);
在int kkk=0;这一行设置断点,发现:
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处设置断点,重新调试
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函数中添加如下代码:
++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);