redis6.0.5之lzf阅读笔记4--调试

相关源码:
D:\mysourcecode\mytestcode\lzf>tree /F
卷 新加卷 的文件夹 PATH 列表
卷序列号为 BA81-13D2
D:.
    lzf.h
    lzfP.h
    lzf_c.c
    lzf_d.c
    TestLzf.c
没有子文件夹
lzf.h,lzfP.h,lzf_c.c,lzf_d.c都是原文件
只有TestLzf.c 是自写测试文件
具体如下:

#include<stdio.h>
#include<string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include "lzfP.h"
// gcc lzf_d.c lzf_c.c  TestLzf.c   -o  Testlzf -g
int main(int argc, char *argv[])
{
    char *s1 = "123123123123456kk1234abcdefg12345hijklmnopqrstuvwxyz"; 
    size_t inlen = strlen(s1);
    printf("\n inlen=%d \n",inlen);
    char  output[inlen];
    unsigned int comprlen =  lzf_compress (s1,  inlen,  &output , inlen+100);
    printf("\n comprlen = %d \n",comprlen);
    printf("\n output=%s \n",output);
    char  deoutput[inlen];
    unsigned int decomprlen = lzf_decompress (&output,  comprlen, &deoutput, inlen+100);
    printf("\n deoutput:%s \n",deoutput);
    return 0;
}

编译源文件得到可执行文件
[root@localhost lzf]# gcc lzf_d.c lzf_c.c  TestLzf.c   -o  Testlzf -g 
[root@localhost lzf]# ./Testlzf 
 inlen=52 
 comprlen = 47 
 output=123
 deoutput:123123123123456kk1234abcdefg12345hijklmnopqrstuvwxy 
[root@localhost lzf]# 

进行gdb调试,省略个人调试诸多单步,直接呈现结果,实际调试过程都是单步的

[root@localhost lzf]# gdb ./Testlzf 
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
Copyright (C) 2013 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 "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /sourcecode/mytestcode/lzf/Testlzf...done.
(gdb) l lzf_compress
100              void *out_data, unsigned int out_len
101    #if LZF_STATE_ARG
102                  , LZF_STATE htab
103    #endif
104                  )
105    {
106    #if !LZF_STATE_ARG
107      LZF_STATE htab;
108    #endif
109      const u8 *ip = (const u8 *)in_data;
(gdb) b 321
Breakpoint 1 at 0x401479: file lzf_c.c, line 321.
(gdb) r
Starting program: /sourcecode/mytestcode/lzf/./Testlzf 

 inlen=52 

Breakpoint 1, lzf_compress (in_data=0x401838, in_len=52, out_data=0x7fffffffe3d0, out_len=152) at lzf_c.c:321
321      op [- lit - 1] = lit - 1; /* end run */
(gdb) n
322      op -= !lit; /* undo run if length is zero */
(gdb) n
324      return op - (u8 *)out_data;
(gdb) p *(u8 *)out_data@15
$1 = "\002\061\062\063\340\000\002\004\064\065\066kk \r"
(gdb) p *(u8 *)out_data@47
$2 = "\002\061\062\063\340\000\002\004\064\065\066kk \r\a4abcdefg@\n\023\065hijklmnopqrstuvwxyz"
(gdb) c
Continuing.

 comprlen = 47 

 output=123  没有显示全,出现了\000导致显示中断

 deoutput:123123123123456kk1234abcdefg12345hijklmnopqrstuvwxyz 
[Inferior 1 (process 5781) exited normally]
(gdb) 

 

posted on 2021-07-12 17:28  子虚乌有  阅读(112)  评论(0)    收藏  举报