前言

呵呵 最近因为有一些需求使用到了 vsftpd, 呵呵 因此 对于其中有一些内容 有一些 好奇 

因此 想要搭建一个 vsftpd 的调试环境, 客户端 和 服务端 一起来调试一下 

 

 

我这里环境是 : Ubuntu 12.04.3 LTS + vsftpd 3.0.2 

当然 似乎是在 Ubuntu 12.04.3 LTS 才有这一系列的编译问题, 我放到了 另外的一台虚拟机 Ubuntu 16.04.1 LTS 是直接类似于 INSTALL 文件中所述, make 就完事了 

 

 

vsftpd 的编译 

呵呵 编译的时候 碰到了 奇奇怪怪的问题, 如下的方式 仅仅是解决了当时编译的时候碰到的问题  

 

1. cannot find crt1.o: No such file or directory

/usr/bin/gold: cannot find Scrt1.o: No such file or directory
/usr/bin/gold: cannot find crt1.o: No such file or directory
/usr/bin/gold: cannot find crti.o: No such file or directory

g95 ld: cannot find crt1.o: No such file or directory

 

在本地 查找了一下 crti.o 发现在另外的一个文件夹下面存在, 再看了一下 这缺少的这三个文件都有, 呵呵 参照这位大哥的 创建了一个 软连接, 问题解决了, 可能默认 搜索的是 /usr/lib64 下面吧 

root@master:~/CLionProjects/vsftpd# find / -name crti.o
/usr/lib/x86_64-linux-gnu/crti.o
/usr/lib32/crti.o

 

 

2. libmpc.so.3: cannot open shared object file: No such file or directory

gcc -fPIC -c main.c -g -idirafter dummyinc -I/usr/include/x86_64-linux-gnu/
/opt/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.0.0/cc1: error while loading shared libraries: libmpc.so.3: cannot open shared object file: No such file or directory

呵呵 这个同样也是 参照文章,  【Linux】【编译】libmpc.so.3: cannot open shared object file: No such file or directory 

 

搜索一下 libmpc 相关的文件 如下, 再来看一下 其中的一些文件的情况 

root@master:~# find / -name libmpc*
/usr/lib/x86_64-linux-gnu/libmpc.so.2.0.0
/usr/lib/x86_64-linux-gnu/libmpc.so.2
/usr/share/doc/libmpc2
/opt/gcc-trunk/lib64/lib64/libmpc.so.2.0.0
/opt/gcc-trunk/lib64/lib64/libmpc.so
/opt/gcc-trunk/lib64/lib64/libmpc.so.2
/opt/gcc-trunk/lib64/lib64/libmpc.a
/var/lib/dpkg/info/libmpc2:amd64.shlibs
/var/lib/dpkg/info/libmpc2:amd64.list
/var/lib/dpkg/info/libmpc2:amd64.postinst
/var/lib/dpkg/info/libmpc2:amd64.md5sums
/var/lib/dpkg/info/libmpc2:amd64.postrm

 

libmpc.so.2 也是一个软连接, 呵呵 县创建一个 libmpc.so.3 试试, 没想到是 直接过了 

root@master:~# ll /usr/lib/x86_64-linux-gnu/ | grep libmpc
lrwxrwxrwx   1 root root       15 Dec  1  2014 libmpc.so.2 -> libmpc.so.2.0.0
-rw-r--r--   1 root root    85176 Oct 19  2011 libmpc.so.2.0.0

 

 

3. 编译出来的可执行文件不可调式 

然后 执行可执行文件, 带上配置文件, 也可以执行 

但是在 main.c 里面打上一个断点, 呵呵 断点变灰了 

首先看了一下 Makefile, 这里的额 CFLAGS 有两套配置, 一套是 -g[编译调试版本], 另外一套是 编译生产版本的, 呵呵 切换了一下 改成了 -g 

为了确认我们 生成的 目标文件是包含了调试信息的, 可以使用 objdump 查看一下 .o, 如果是 编译的时候 不带 -g, 是灭有这些调试信息的  

root@master:~/CLionProjects/vsftpd# objdump -S main.o

main.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <main>:
static void env_init(void);
static void limits_init(void);

int
main(int argc, const char* argv[])
{
   0:	55                   	push   %rbp
   1:	48 89 e5             	mov    %rsp,%rbp
   4:	48 81 ec 50 02 00 00 	sub    $0x250,%rsp
   b:	89 bd bc fd ff ff    	mov    %edi,-0x244(%rbp)
  11:	48 89 b5 b0 fd ff ff 	mov    %rsi,-0x250(%rbp)
  struct vsf_session the_session =
  18:	48 8d 95 e0 fd ff ff 	lea    -0x220(%rbp),%rdx
  1f:	b8 00 00 00 00       	mov    $0x0,%eax
  24:	b9 3c 00 00 00       	mov    $0x3c,%ecx
  29:	48 89 d7             	mov    %rdx,%rdi
  2c:	f3 48 ab             	rep stos %rax,%es:(%rdi)
  2f:	c7 85 00 fe ff ff ff 	movl   $0xffffffff,-0x200(%rbp)
  36:	ff ff ff 
  39:	c7 85 10 fe ff ff ff 	movl   $0xffffffff,-0x1f0(%rbp)
  40:	ff ff ff 
  43:	c7 85 30 fe ff ff 01 	movl   $0x1,-0x1d0(%rbp)
  4a:	00 00 00 
  4d:	c7 85 60 fe ff ff 01 	movl   $0x1,-0x1a0(%rbp)
  54:	00 00 00 
  57:	c7 85 a0 fe ff ff ff 	movl   $0xffffffff,-0x160(%rbp)
  5e:	ff ff ff 
  61:	c7 85 a4 fe ff ff ff 	movl   $0xffffffff,-0x15c(%rbp)
  68:	ff ff ff 
  6b:	c7 85 a8 fe ff ff ff 	movl   $0xffffffff,-0x158(%rbp)
  72:	ff ff ff 
  75:	c7 85 f0 fe ff ff 01 	movl   $0x1,-0x110(%rbp)
  7c:	00 00 00 
  7f:	c7 85 f4 fe ff ff ff 	movl   $0xffffffff,-0x10c(%rbp)
  86:	ff ff ff 
  89:	c7 85 f8 fe ff ff ff 	movl   $0xffffffff,-0x108(%rbp)
  90:	ff ff ff 
  93:	c7 85 60 ff ff ff ff 	movl   $0xffffffff,-0xa0(%rbp)
  9a:	ff ff ff 
  9d:	c7 85 64 ff ff ff ff 	movl   $0xffffffff,-0x9c(%rbp)
  a4:	ff ff ff 
  a7:	c7 45 b4 ff ff ff ff 	movl   $0xffffffff,-0x4c(%rbp)
  ae:	c7 45 b8 ff ff ff ff 	movl   $0xffffffff,-0x48(%rbp)
    /* Secure connection state */
    0, 0, 0, 0, 0, INIT_MYSTR, 0, -1, -1,
    /* Login fails */
    0
  };
  int config_loaded = 0;
  b5:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%rbp)
  int i;
  tunables_load_defaults();
  bc:	b8 00 00 00 00       	mov    $0x0,%eax
  c1:	e8 00 00 00 00       	callq  c6 <main+0xc6>
  /* This might need to open /dev/zero on systems lacking MAP_ANON. Needs
   * to be done early (i.e. before config file parse, which may use
   * anonymous pages
   */
  vsf_sysutil_map_anon_pages_init();
  c6:	e8 00 00 00 00       	callq  cb <main+0xcb>
   * loaded in the order encountered. -o opt=value options are loading in the
   * order encountered, including correct ordering with respect intermingled
   * config files.
   * If we see -v (version) or an unknown option, parsing bails and exits.
   */

 

然后 另外就是 找了一篇查看 executable 是否可调式的判断依据的文章 

Linux下查看.so和可执行文件是否debug编译 

看了一下 生成的可执行文件 , 可以看到的是 这里是灭有 debug 相关的 section 的信息的  

root@master:~/CLionProjects/vsftpd# readelf -S vsftpd
There are 29 section headers, starting at offset 0x27a78:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000000238  00000238
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.ABI-tag     NOTE             0000000000000254  00000254
       0000000000000020  0000000000000000   A       0     0     4
  [ 3] .dynsym           DYNSYM           0000000000000278  00000278
       0000000000000cf0  0000000000000018   A       4     1     8
  // 省略一部分输出 
  [27] .note.gnu.gold-ve NOTE             0000000000000000  0002795c
       000000000000001c  0000000000000000           0     0     4
  [28] .shstrtab         STRTAB           0000000000000000  00027978
       00000000000000fe  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

 

然后 之后 又找了一篇文章 

使用gcc -g编译,gdb调试时仍然存在“no debug symbols found”的错误

今天为调试一段代码,使用gcc将程序用-g选项重新编译。但是使用gdb进行debug时,仍然出现“no debug symbols found”的错误。仔细检查了一下Makefile,原来后面定义的连接选项中指定了-s。gcc的文档中说明如下:

 

-s Remove all symbol table and relocation information from the executable.

去掉-s后,可以用gdb进行调试了

呵呵 对比了一下 LINK 的参数, 呵呵 这里也有 -s 参数, 怕不是 就是这个原因 

然后 去掉了 LINK 参数, 再次尝试 , 然后 readelf 查看可执行文件信息 , 可以看到 多了大概是个 section, 多出来的一部分是 .debug 相关的 section 

root@master:~/CLionProjects/vsftpd# readelf -S vsftpd
There are 37 section headers, starting at offset 0x5ff38:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000000238  00000238
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.ABI-tag     NOTE             0000000000000254  00000254
       0000000000000020  0000000000000000   A       0     0     4
  [ 3] .dynsym           DYNSYM           0000000000000278  00000278
       0000000000000cf0  0000000000000018   A       4     1     8
  // 省略部分信息 
       0000000000000750  0000000000000000           0     0     1
  [30] .debug_line       PROGBITS         0000000000000000  000485dd
       0000000000004654  0000000000000000           0     0     1
  [31] .debug_str        PROGBITS         0000000000000000  0004cc31
       0000000000007511  0000000000000001  MS       0     0     1
  [32] .debug_ranges     PROGBITS         0000000000000000  00054142
       0000000000000360  0000000000000000           0     0     1
  [33] .note.gnu.gold-ve NOTE             0000000000000000  000544a4
       000000000000001c  0000000000000000           0     0     4
  [34] .symtab           SYMTAB           0000000000000000  000544c0
       00000000000067b0  0000000000000018          35   353     8
  [35] .strtab           STRTAB           0000000000000000  0005ac70
       0000000000005169  0000000000000000           0     0     1
  [36] .shstrtab         STRTAB           0000000000000000  0005fdd9
       000000000000015c  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

 

 

大功告成 

02 vsftpd 的调试环境的搭建_ftp

 

 

完 

 

参考  

g95 ld: cannot find crt1.o: No such file or directory

【Linux】【编译】libmpc.so.3: cannot open shared object file: No such file or directory 

Linux下查看.so和可执行文件是否debug编译 

使用gcc -g编译,gdb调试时仍然存在“no debug symbols found”的错误