Several GDB tips ZZ

Source: Internet
Author: User
Http://blog.csdn.net/absurd/

GDB is more powerful than a debugger with a GUI, so it is more complicated to use. On the one hand, it has a poor affinity. After all, it is intended for programmers and does not need to be fooled. On the other hand, there are too many commands for it. We often get started with it by remembering just a few common commands and failing to make full use of its potential. Today, I want to debug a piece of arm assembly code. It is very troublesome to debug the assembly code by using conventional methods. It took me some time to look at the help of GDB and I found several useful techniques. Here I will take a note.

 

1. Use custom commands. There are many built-in commands in GDB, which follow the Unix principle and each command has only one basic function. The command is fine-grained and reusable. Organize these basic commands to form more powerful commands. This can be implemented using define, for example:

(GDB) define Nid

Type commands for definition of "NID ".

End with a line saying just "end ".

> Ni

> Disassemble $ PC + 16

> End

 


 

2. Multiple windows. The GUI debugger can open multiple small windows to display registers, assemblies, and source code. It can also be done in GDB, but only two windows can be displayed at the same time. It is convenient to try it. The basic commands are as follows:

A) 'layout src' only displays the source code window.

B) 'layout ASM 'Only displays the assembly code window.

C) 'layout split': displays the source code and assembly code windows.

D) 'layout regs 'displays the register and source code windows, or registers and assembly code windows.

E) switch between 'layout next' and 'layout prev.

F) Ctrl + L refresh the screen.

G) 'C-x 1' Single Window mode.

H) 'C-x 2' dual-window mode.

I) 'C-x a' returns to the traditional mode.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.