第04课:GDB常用命令详解(上)

本课的核心内容如下:

  run命令

  continue命令

  break命令

  backtrace与frame命令

  info break、enable、disable和delete命令

  list命令

  print和ptype命令

为了结合实践,这里以调试Redis源码为例来介绍没一个命令,这里先介绍一些常用命令的基础用法,某些命令的高级用法会在后面讲解。

Redis的最新源码下载地址可以在Redis官网(Redis中文网)获得,使用wget命令将Redis源码文件下载下来:

第04课:GDB常用命令详解(上)

解压:tar zxvf redis-5.0.3.tar.gz 

进入生成的 redis-5.0.3 目录使用makefile命令进行编译。makefile命令是Linux程序编译基本的命令,由于本课程的重点是Linux调试,如果读者不熟悉Linux编译可以通过互联网或相关书籍补充一下知识。

步骤:cd redis-5.0.3/    

   make -j 4 

      cd src 

      make test

 

然后启动 redis-server

第04课:GDB常用命令详解(上)

4.1  run命令

  默认情况下,前面的课程中我们说gdb filename 命令知识个附加的一个调试文件,并没有启动这个程序,需要输入run命令(简写为r)启动这个程序。

(gdb) r Starting program: /home/wzq/Desktop/redis-5.0.3/src/redis-server [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 21463:C 09 Jan 2019 14:33:20.281 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 21463:C 09 Jan 2019 14:33:20.281 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=21463, just started 21463:C 09 Jan 2019 14:33:20.281 # Warning: no config file specified, using the default config. In order to specify a config file use /home/wzq/Desktop/redis-5.0.3/src/redis-server /path/to/redis.conf 21463:M 09 Jan 2019 14:33:20.282 * Increased maximum number of open files to 10032 (it was originally set to 1024). [New Thread 0x7ffff67ff700 (LWP 21467)] [New Thread 0x7ffff5ffe700 (LWP 21468)] [New Thread 0x7ffff57fd700 (LWP 21469)] _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 21463 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 21463:M 09 Jan 2019 14:33:20.283 # Server initialized 21463:M 09 Jan 2019 14:33:20.283 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 21463:M 09 Jan 2019 14:33:20.283 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 21463:M 09 Jan 2019 14:33:20.283 * Ready to accept connections

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zydffw.html