Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2159787
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2011-11-07 14:18:05

环境: ubuntu 9.04 或 redhat 9.0
bochs: bochs-2.4.6.tar.gz 更新了bochs-2.6.8的安装
一、ubuntu 下apt安装
1.1 编译环境
  1. cong@msi:/work/os/bak/bochs-2.6.8$ sudo apt-get install build-essential  
  2. cong@msi:/work/os/bak/bochs-2.6.8$ sudo apt-get install xorg-dev        -->这个必须安装
  3. cong@msi:/work/os/bak/bochs-2.6.8$ sudo apt-get install libgtk2.0-dev
1.2 编译不带任何调试的bochs
  1. cong@msi:/work/os/bak/bochs-2.6.8$ mkdir install          -->以后install把生成的bochs都放在这个目录下面
  2. cong@msi:/work/os/bak/bochs-2.6.8$ ./configure --prefix=`pwd`/install
  3. cong@msi:/work/os/bak/bochs-2.6.8$ make -j8               -->直接编译即可
  4. cong@msi:/work/os/bak/bochs-2.6.8$ make install
1.3 出错及问题解决
  1. a.出错: ERROR: X windows gui was selected, but X windows libraries were not found.
  2.  root@ubuntu:~# aptitude install xorg-dev

  3. b.出错: ERROR: pkg-config was not found, or unable to access the gtk+-2.0 package.
  4.  root@ubuntu:~# aptitude install libgtk2.0-dev

  5. c.在configure时同时配了debugger&&gdb-stub会有如下错误./configure --enable-gdb-stub --enable-disasm --enable-debugger
  6.  configure: error: --enable-debugger and --enable-gdb-stub are mutually exclusive
1.4 编译带asm调试功能的bochs
  1. cong@msi:/work/os/bak/bochs-2.6.8_asm$ ./configure --prefix=`pwd`/install --enable-debugger --enable-disasm
如果加上--enable-plugins会出现 
>>PANIC<< dlopen failed for module 'unmapped': file not found
1.5 编译带gdb调试功能的bochs
  1. cong@msi:/work/os/bak/bochs-2.6.8_gdb$ ./configure --prefix=`pwd`/install --enable-disasm --enable-gdb-stub
  2. cong@msi:/work/os/bak/bochs-2.6.8_gdb$ make -j8
  3. cong@msi:/work/os/bak/bochs-2.6.8_gdb$ make install
1.6 注意:
a.用apt-get install 安装的bochs 版本不能调试,如果需要加调试功能需要从源码添加编译选项
 b. Linux 没有bochsbgb工具,在configure时加了enable-debugger选项,重新编译后的bochs就带有调试功能。

二、Redhat 9.0 编译安装
环境: RedHat 9.0
gcc版本: gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

2.1 编译安装 bochs 不带调试信息
tar xvfz bochs-2.3.5.tar.gz
cd bochs-2.3.5
./configure --prefix=/opt/bochs/run
make ; make install

2.2编译安装 bochs 带汇编调试
./configure --prefix=/opt/bochs/debug --enable-plugins --enable-debugger --enable-disasm
make 
make install

2.3 编译安装 bochs 带gdb调试
./configure --prefix=/opt/bochs/gdbstub --enable-plugins --enable-disasm --enable-gdb-stub 
make
make install

注意:这里编译两次bochs 是因为如果一步到位configure 
./configure --enable-gdb-stub --enable-disasm --enable-debugger 
它会很生气
configure: error: --enable-debugger and --enable-gdb-stub are mutually exclusive

2.4 gdb+bochs调试linux0.11的总出现缺页中断问题
a. bochs-2.6.8下修改 src/gdbstub.cc,增加如下红色部分

b. gdbstub.cc L492
  1. else if (last_stop_reason == GDBSTUB_STOP_NO_REASON)
  2. {
  3.    write_signal(&buf[1], SIGSEGV);
  4. }
c. 编译安装之后
启动gdb,在gdb的shell中输入 handle SIGSEGV nostop noprint ignore 即可
以上出自《gdb+bochs调试linux0.11的总出现缺页中断问题。》
http://blog.chinaunix.net/uid-7480243-id-2051574.html

3. 在RedHat9.0下编译时会出现如下的错误:
/usr/X11R6/lib/libXrandr.so: undefined reference to `XextAddDisplay'
/usr/X11R6/lib/libXrandr.so: undefined reference to `XextFindDisplay'
/usr/X11R6/lib/libXrandr.so: undefined reference to `XRenderSetSubpixelOrder'
/usr/X11R6/lib/libXrandr.so: undefined reference to `XextRemoveDisplay'
/usr/X11R6/lib/libXrandr.so: undefined reference to `XMissingExtension'
  1. 提示缺少库,编个小脚本练习一下。
  2. #******test.sh ******#
  3. #!/bin/sh
  4. for file in `find /usr/X11R6/lib/*.a`
  5. do
  6. echo $file
  7. nm $file | grep XextAddDisplay
  8. done

  9. 执行:
  10. [root@localhost tmp]# ./test.sh
  11. /usr/X11R6/lib/libGL.a
  12.          U XextAddDisplay
  13.          U XextAddDisplay
  14. /usr/X11R6/lib/libXext.a
  15. 00000060 T XextAddDisplay
  16.          U XextAddDisplay
  17. /usr/X11R6/lib/libXfontcache.a
  18.          U XextAddDisplay
  19. /usr/X11R6/lib/libXft.a
  20. /usr/X11R6/lib/libXi.a
  21.          U XextAddDisplay
  22. /usr/X11R6/lib/libXinerama.a
  23.          U XextAddDisplay

  24. 上述打印中:
  25.          U XextAddDisplay 说明XextAddDisplay 没有定义
  26.          00000060 T XextAddDisplay 说明 XextAddDisplay己定义
依次grep 可以找出缺失的两个库 -lXext -lXrender 在Makefile中加上就可以了。  
GUI_LINK_OPTS_X = $(X_LIBS) $(X_PRE_LIBS) -lX11 $(XPM_LIB) -lXrandr -lXext -lXrender

三.bochs调试指令
  1. <bochs:1> help
  2. h|help - show list of debugger commands
  3. h|help command - show short command description
  4. -*- Debugger control -*-
  5.     help, q|quit|exit, set, instrument, show, trace, trace-reg,
  6.     trace-mem, u|disasm, ldsym, slist
  7. -*- Execution control -*-
  8.     c|cont|continue, s|step, p|n|next, modebp, vmexitbp
  9. -*- Breakpoint management -*-
  10.     vb|vbreak, lb|lbreak, pb|pbreak|b|break, sb, sba, blist,
  11.     bpe, bpd, d|del|delete, watch, unwatch
  12. -*- CPU and memory contents -*-
  13.     x, xp, setpmem, writemem, crc, info,
  14.     r|reg|regs|registers, fp|fpu, mmx, sse, sreg, dreg, creg,
  15.     page, set, ptime, print-stack, ?|calc
  16. -*- Working with bochs param tree -*-
  17.     show "param", restore
3.1 查看内存中的数据
  1. <bochs:2> help x
  2. x /nuf <addr> - examine memory at linear address
  3. xp /nuf <addr> - examine memory at physical address
  4.     nuf is a sequence of numbers (how much values to display)
  5.     and one or more of the [mxduotcsibhwg] format specificators:
  6.     x,d,u,o,t,c,s,i select the format of the output (they stand for hex, decimal, unsigned, octal, binary, char, asciiz, instr)
  7.     b,h,w,g select the size of a data element (for byte, half-wordword and giant word)
  8.     m selects an alternative output format (memory dump)
a. 例如要查看0x102000处的数据-->按16进制4字节打印
  1. <bochs:3> x /8wx 0x102000
  2. 0x00102000 <bogus+ 0>:    0x00000007    0x00001007    0x00002007    0x00003007
  3. 0x00102010 <bogus+ 16>:    0x00004007    0x00000000    0x00000000    0x00000000
b.例如要查看0x102000处的数据-->按16进制单字节打印
  1. <bochs:4> x /8bx 0x102000
  2. 0x00102000 <bogus+ 0>:    0x07    0x00    0x00    0x00    0x07    0x10    0x00    0x00
3.2 反汇编
  1. <bochs:5> help u
  2. u|disasm [/count] <start> <end> - disassemble instructions for given linear address
  3.     Optional 'count' is the number of disassembled instructions
  4. u|disasm switch-mode - switch between Intel and AT&T disassembler syntax
  5. u|disasm hex on/off - control disasm offsets and displacements format
  6. u|disasm size = n - tell debugger what segment size [16|32|64] to use
  7.        when "disassemble" command is used.
a. 例如要反汇编当前指令之后的32条指令
  1. <bochs:6> u /32
  2. 00100035: ( ): add eax, 0x00001000 ; 0500100000
  3. 0010003a: ( ): cmp edi, 0x00104000 ; 81ff00401000
b. 例如要反汇编0x100000之后的32条指令
  1. <bochs:7> u /32 0x100000
  2. 00100000: ( ): cld ; fc
  3. 00100001: ( ): mov eax, 0x00000018 ; b818000000
3.3设断点
  1. <bochs:8> help b
  2. p|pb|break|pbreak <addr> - set a physical address instruction breakpoint
  3. <bochs:9> help lb
  4. lb|lbreak <addr> - set a linear address instruction breakpoint
lb 0x100000
b 0x7c00
阅读(5680) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~