Command Summary -gcc gdb git

li # gcc command summary

One step compile: gcc hello.c -o hello

Pretreatment -E (.i) compiled -S (.s) compilation -c (.o) -o connection

Pretreatment

gcc -E hello.c -o hello.i -E: execute only the preprocessor

-o: The resulting output and specify the output file name

Compiled into assembly code

gcc -S hello.c (.i) -o hello.s -S: The C code into assembly code

compilation:

gcc -c hello.c -o hello.o -c: only the compilation operation, the connecting operation is not performed

connection:

gcc hello.o -o hello


-o : The resulting output and specify the output file name

-O0, -O1, -O2, -O3 : four levels of compiler optimization options, -O0 indicating no optimization, -O1 default values, -O3 highest level of optimization

-g : just a compiler, at compile time, generate debugging information

Disassembly:

gcc hello.c -g -o hello

Objdump -S -dx hello >hello.s

-S: display assembly code displays the time when the original C language source code

Unicode given UTF-8

unicode is encoded, and a storage utf-8

unicode encoding (hexadecimal) UTF-8 byte stream (binary)
0000 - 007F 0xxxxxxx
0080 - 07FF 110xxxxx 10xxxxxx
0800 - FFFF 1110xxxx 10xxxxxx 10xxxxxx

uft-8 obtained by coding the number of bytes sure, it may be 1 byte, 3 bytes may be. But the biggest benefit is utf-8 compatible and ASCII code, the letters are stored in a byte, so now widely used.

For the UTF-8 encoding any byte B, B if the first bit is 0, then B independently represent a character (ASCII code);
if B 1 is the first bit, the second bit is 0, then B one byte (non-ASCII characters) in a multi-byte character;
if the first two bits B is 1, the third bit is 0, then B is a two-byte character represented by the first byte;
If the top three B is 1, the fourth bit is 0, the character B is three bytes in the first byte;
if the first four bits of B 1, fifth bit is 0, then B character is represented by four bytes in the first byte;
therefore, any byte UTF-8 encoding, in accordance with the first, may determine whether to ASCII characters; according to the previous two, it can be determined that the word whether it is a character code section of the first byte; the first four (if the first two bits are 1), may determine that the first byte is a byte character encoding, and may be determined by the character corresponding to several It represents bytes; the first five (if the first four bits 1), there can be determined whether the encoded data error or whether there is an error during transmission.

GDB
can first use readelf -a bomb look at the general structure of the executable file. A first instruction position than main
(gdb) L (IST) (gdb) B main breakpoint (gdb) R & lt continued operation c
(gdb) arranged along disassemble main / mc and asm / r see hex code 16
(gdb) X / 15i main instructions can be viewed by x / I
(gdb) x / 15 addresses x / s data can be viewed hexadecimal string x
(gdb) display / 10i main command automatically displays the current assembly instruction about to execute
(gdb) Ni; single machine instruction executed next n step C a statement (gdb) si: single step into a single step s machine instruction statement a C?
(GDB) the RIP Print $ $ EAX  antihuman! !
All information (gdb) info reg info proc all see this process
(gdb) layout prev | next | <layout_name> to change the layout src / asm / Split / regs
(gdb) the SET-flavors the intel into the Disassembly Intel format

ELF file analysis

readelf see Help

readelf - H reading ELF file header analysis

readelf - S symbol table (Dynamic Analysis symbols Symbol)

- the X- see Byte

- the p- looking string

readelf - A look at all the information

readelf <option(s)> elf-file(s)

-a -all equivalent to simultaneously: -h -l -S -s -r -d -V -A -I
display -h --file-header ELF header
-l --program-headers shows the program header
-S --section-headers display section header
-t --section-details display section details
-s -syms symbol table (symbol table)
-R & lt -relocs relocation information display
-d -dynamic display dynamic section (dynamic sectionTop)
- x --hex-dump = <number | name>
are displayed in the form of output bytes <number | name> contents of the specified section
-p --string-dump = <number | name>
display output <number as a string | name > contents of the specified section
-R --relocated-dump = <number | name>
display output <number of bytes in the form of a relocation | name> specifies section

Released seven original articles · won praise 3 · Views 469

Guess you like

Origin blog.csdn.net/qq_39600733/article/details/103938038