computer system 2

//ex4
#include "stdio.h"
int main()
{   
    float a1=0x8000001,a2=0x8000007,a3=0x8000011,a4=0x8000017;
    float b1=0x8000008,b2=0x8000018,b3=0x8000009,b4=0x8000019;
    float c1=0x800000c,c2=0x800000d;
    float   g=1234567890;
    double  h=1234567890;
    printf(" %x   %x   %x    %x\n ",(int)a1,(int)a2,(int)a3,(int)a4);
    printf(" %x   %x   %x    %x\n ",(int)b1,(int)b2,(int)b3,(int)b4);
    printf(" %x   %x \n ",(int)c1,(int)c2);

    printf("  %f\n ",g);
    printf("  %f\n ",h);

    return 0;
}
student1@506-55:~$ gcc -O0 ex4.c -m32 -g -o ex4
student1@506-55:~$ objdump -S ex4>ex4.txt
student1@506-55:~$ gdb ex4
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ex4...done.
(gdb) b 15
Breakpoint 1 at 0x80485b0: file ex4.c, line 15.
(gdb) run
Starting program: /home/student1/ex4 
 8000000   8000000   8000010    8000010
  8000000   8000020   8000010    8000020
  8000010   8000010 
   1234567936.000000
   1234567890.000000

Breakpoint 1, main () at ex4.c:16
16		return 0;
(gdb) p &c2
$1 = (float *) 0xbfffef70
(gdb) x/1xw &c2
0xbfffef70:	0x4d000001
(gdb) x/1xw &c1
0xbfffef6c:	0x4d000001
(gdb) x/1xw &b3
0xbfffef64:	0x4d000001
(gdb) x/1xw &b4
0xbfffef68:	0x4d000002
(gdb) x/1xw &b4
0xbfffef68:	0x4d000002
(gdb) x/1xw &b2
0xbfffef60:	0x4d000002
(gdb) x/1xw &b1
0xbfffef5c:	0x4d000000
(gdb) x/1xw &a3
0xbfffef54:	0x4d000001
(gdb) x/1xw &a4
0xbfffef58:	0x4d000001
(gdb) x/1xw &g
0xbfffef74:	0x4e932c06
(gdb) x/1xw &h
0xbfffef78:	0xb4800000
  • 4xb 连续输出4组,按16进制,每组1个字节,小端机器显示 要注意顺序
    1xw 连续输出1组,按16进制,每组4个字节

  • ~$ gcc -O0 ex4.c -m32 -g -o ex4
    带上-g 之后才能进行调试,否则显示没有符号表

  • gdb设置断点后要run

//ex5
#include <stdio.h>
int main()
{
    printf("hello, world\n");
}

vim 行号的显示与隐藏
https://www.cnblogs.com/star520/p/9081357.html

linux 下的 .a 文件 .o 文件 是什么文件?各有什么作用?.o 就是object, 也就相当于windows下编译的obj文件, 俗称目标文件.

.a 就是archive, 也就相当于windows的VC下编译的lib文件, 俗称静态库文件.

.o文件是链接文件,.a是静态库文件,靠.o文件生成,作为一个库为外部程序提供函数,接口。
生成.o文件:
gcc -c test.o test.c
生成.a文件:
ar cqs test.a test.o

.o 就相当于windows里的obj文件 ,一个.c或.cpp文件对应一个.o文件
.a 是好多个.o合在一起,用于静态连接 ,即STATIC mode,多个.a可以链接生成一个exe的可执行文件
.so 是shared object,用于动态连接的,和windows的dll差不多,使用时才载入。

原文链接:http://blog.sina.com.cn/s/blog_935ccd710101iu3s.html

~$ vim ex5.i

ex5.i~$ vim ex5.s
在这里插入图片描述ex5.o

GCC全过程详解+剖析生成的.o文件
https://blog.csdn.net/gt1025814447/article/details/80442673
在这里插入图片描述
查看可执行文件ex5
https://www.cnblogs.com/little-ant/p/3658692.html

student1@506-55:~$ ldd ex5
	linux-gate.so.1 =>  (0xb7f14000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7d44000)
	/lib/ld-linux.so.2 (0xb7f16000)
student1@506-55:~$ nm ex5
0804a01c B __bss_start
0804a01c b completed.7209
0804a014 D __data_start
0804a014 W data_start
08048350 t deregister_tm_clones
080483c0 t __do_global_dtors_aux
08049f0c t __do_global_dtors_aux_fini_array_entry
0804a018 D __dso_handle
08049f14 d _DYNAMIC
0804a01c D _edata
0804a020 B _end
080484a4 T _fini
080484b8 R _fp_hw
080483e0 t frame_dummy
08049f08 t __frame_dummy_init_array_entry
080485c4 r __FRAME_END__
0804a000 d _GLOBAL_OFFSET_TABLE_
         w __gmon_start__
080484d0 r __GNU_EH_FRAME_HDR
080482a8 T _init
08049f0c t __init_array_end
08049f08 t __init_array_start
080484bc R _IO_stdin_used
         w _ITM_deregisterTMCloneTable
         w _ITM_registerTMCloneTable
08049f10 d __JCR_END__
08049f10 d __JCR_LIST__
         w _Jv_RegisterClasses
080484a0 T __libc_csu_fini
08048440 T __libc_csu_init
         U __libc_start_main@@GLIBC_2.0
0804840b T main
         U puts@@GLIBC_2.0
08048380 t register_tm_clones
08048310 T _start
0804a01c D __TMC_END__
08048340 T __x86.get_pc_thunk.bx

文本文件和二进制文件的差异和区别
https://blog.csdn.net/colourful_sky/article/details/80334250

//ex5_2
#include "stdio.h"
int main()
{  int x=3,y=5,z;
   z=x+y;
   printf("z=%d\n",z);
   return 0;
}
student1@506-55:~$ gcc -O0 ex5_2.c -m32 -g -o ex5_2
student1@506-55:~$ objdump -S ex5_2>ex5_2.txt
student1@506-55:~$ gdb ex5_2
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ex5_2...done.
(gdb) break 6
Breakpoint 1 at 0x8048448: file ex5_2.c, line 6.
(gdb) run
Starting program: /home/student1/ex5_2 
z=8

Breakpoint 1, main () at ex5_2.c:6
6	   return 0;
(gdb) i r esp ebp
esp            0xbfffef70	0xbfffef70
ebp            0xbfffef88	0xbfffef88
(gdb) x/zxw $esp
0xbfffef70:	0x00000001
(gdb) x/28xb $esp
0xbfffef70:	0x01	0x00	0x00	0x00	0x03	0x00	0x00	0x00
0xbfffef78:	0x05	0x00	0x00	0x00	0x08	0x00	0x00	0x00
0xbfffef80:	0xdc	0xb3	0xfb	0xb7	0xa0	0xef	0xff	0xbf
0xbfffef88:	0x00	0x00	0x00	0x00
(gdb) x/7xw $esp
0xbfffef70:	0x00000001	0x00000003	0x00000005	0x00000008
0xbfffef80:	0xb7fbb3dc	0xbfffefa0	0x00000000
(gdb) p x
$1 = 3
(gdb) p &x
$2 = (int *) 0xbfffef74
(gdb) p &y
$3 = (int *) 0xbfffef78
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值