1. source code file search
You can use the following three commands to find the source file for GDB debugging.
Forward-searchRegexp
Search for the keyword Regexp from the first line of the source file and record the row number. This record can be referenced by the next GDB command.
Example: for void
Search Result: 38 void
Next, run the command: List to display 10 lines of content centered on 38 behaviors. (The number of rows to be displayed can be specified)
Search Regexp
Search down from the current row.
Reverse-search Regexp
Search from the last line.
2. View machine commands (assembly)
Disassemble
Disassemble/M hexadecimal display Assembly command
Disassemble/R
Disassemble start, end specifies the start and end addresses
Disassemble start, + length specifies the start address and display Length
You can obtain the address using the following column:
(GDB) info line main
Line 895 of "builtin. c" starts at PC 0x634c and ends at 0x6350.
(GDB) info line * 0x63ff
Line 926 of "builtin. c" starts at PC 0x63e4 and ends at 0x6404.
(gdb) disas 0x634c, 0x6404
Dump of assembler code from 0x32c4 to 0x32e4:
0x32c4 <main+204>: addil 0,dp
0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
0x32cc <main+212>: ldil 0x3000,r31
0x32d0 <main+216>: ble 0x3f8(sr4,r31)
0x32d4 <main+220>: ldo 0(r31),rp
0x32d8 <main+224>: addil -0x800,dp
0x32dc <main+228>: ldo 0x588(r1),r26
0x32e0 <main+232>: ldil 0x3000,r31
End of assembler dump.