Linux advanced debugging and optimization --gdb debug command

Extra

  July 26, 2019 to 27, the company invited "software debugging" and - be author of two books "Georgia beetles compilation software debugging Case histories" Zhang Yinkui teacher "Linux advanced debugging and optimization" training, had the honor of listening to Zhang course. Several years ago the honor have read "software debug" a book, benefit.

  Zhang feels gentle, Qian Qian jade, memory allocation and task management system for Windows and the Linux kernel has a very in-depth understanding of the internal Intel CPU implementation mechanism also has a deep foundation, such as data / code cache, data / code TLB cache, out of order, the MMU mechanism.

  The entire contents of training include:

1) Linux gdb debugger command

2) Linux signal mechanism and application crashes

3) coredump dump and analyze user-mode processes

4) the user mode stack

5) Linux memory management

6) Linux Task Management

7) using kdb / kgdb debug Linux kernel

8) oops and panic

 

Linux gdb commands

1, tracing and debugging

file <executable file> load executable files

break <func> | <file: line> Set code segment breakpoint

watch <addr / variable> breakpoint setting data segment (also called memory hardware breakpoint or breakpoint, Intel CPU support up to four simultaneous data breakpoint setting)

awatch setting data write breakpoint

breakpoint setting data read operation rwatch

info break View Breakpoints

enable <break number> Enable Breakpoint

disable <break number> Disable Breakpoint

delete <break number> Remove Breakpoint

bt (backtrace) to display a function call stack

run executed from the program entry

continue continue to run until the next breakpoint or the end of the program

n (next) next line of code, if subroutine calls, subroutine does not enter the interior

ni next instruction

s (step) single step, next line of code, if the call is a sub-function, into the interior of Functions

si single-step debugging, the next instruction

finish execution stack back to the current function

frame <n> n-th layer selected call stack frames

One frame on the call stack up selection

One call stack frames down the selection

info threads View all threads

thread [thread number] to jump to the specified thread

 

2, info type (observed debug information)

info break break break point display

info watch display watch watchpoint

info files elf file information display

info sharedlibrary display the shared library address map

info registers display CPU general register value

info all-registers all the CPU registers Show

info args parameter Display Function

info var [regex] Display global variable or global variable name string comprising regex

a partial variable info locals

info func [regex] function or display function contained in the function name string regex

info address s display address symbol s

info signals display semaphore

info stack display function call stack, with the role of command bt

info frame [n] display instruction call stack frames

info display display configuration

info line num display lines

info source code file name display

info sources display a list of codes in use

info threads display all the threads

thread apply all <command> Executes the specified command for all threads

thread apply all bt show the call stack for all threads

 

3, show the command to observe the information itself gdb

 

4, x direct observation memory

x/128wx $sp

x/128wi $pc

E.g:

(gdb) x/64wx $sp
0xe342c548: 0x00000000 0xe342cb40 0x00000000 0x00000000
0xe342c558: 0x06f74f8f 0x0c6a543b 0xe342cb40 0xfff333f4
0xe342c568: 0x00000000 0x00000152 0x00000000 0xfff333f4
0xe342c578: 0x00000000 0xe342c67c 0x00000000 0x00000000
0xe342c588: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c598: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c5a8: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c5b8: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c5c8: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c5d8: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c5e8: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c5f8: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c608: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c618: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c628: 0x00000000 0x00000000 0x00000000 0x00000000
0xe342c638: 0x00000000 0x00000000 0x00000000 0x00000000

 

5, list command

Display the code before and after the execution of the current command

disp / 3i $ pc every single step to be executed is displayed next three instructions

 

6, print command

p [/ f] expr - print command is commonly connected C language expression, the expression returns the result

ptype [expr] / [type] Print structure

p addr [num] @ indicates that the print from the starting address addr num bytes

 

7, disassemble disassemble

set disassemble-flavor [att | intel | arm | thumb] assembler instruction format is provided

Linux gdb mode assembly format using the AT & T, can be modified by the assembler format set disassemble-flavor intel

 

8, gdb execute shell commands

Use shell <cmd> or! <Cmd> to format

 

Reference Documents

1、Debugging with gdb

1、gdb quick reference

Guess you like

Origin www.cnblogs.com/justin-y-lin/p/11257246.html