First, the Linux programming environment
1. Program Editor:
Command mode:
I (insert): inserting
A (after): Insert later
X (): Delete character
DD: Delete a row
: line number is specified
:/string: Search string
: Q, go back
: Wq
NDD: deleting n rows
YY: Copy when moving forward
P: Paste
NY: Start copying from current flight
2. GCC
Gcc-s text.c
Gcc-c text.c
gcc-o Text text.c
Gcc-o text TEST1.O text2.o
Second, debugging Tools
1. gdb
Execute debug command: GDB test;
List lines of code: L (list);
Set Breakpoint: B (Break);
Run the program: R (Run);
Continue running: C (continue);
Single-Step operation: N (next);
Exit Gdb:q (quit);
Delete breakpoint: delete, D;
Run shell command: Shell commands
If you want to perform GDB debugging, format: Gcc-wall--c-g
2. Mtrace (Memory tracking)
Mainly used for the log information of malloc, realloc and free;
Operation Steps:
1. Register the environment variable malloc_trace:export command or the putenv () function,
2. The memory allocation is placed between the function mtrace () and the function muntrace () function, the log file will be recorded;
3. Open the log to see memory use memory situation;
Export M alloc_trace =./mymemtrace.log
#include "stdlib.h" #include "stdio.h" #include "string.h" #include "mcheck.h" int main () {<span style= "White-space: Pre "></span>char *tmp; <span style= "White-space:pre" ></span>printf ("hello\n"); <span style= "White-space:pre" ></span>mtrace (); <span style= "White-space:pre" ></span>tmp = (char*) malloc (100); <span style= "White-space:pre" ></span>memset (tmp, 0, 16); <span style= "White-space:pre" ></span>*tmp = 123455; <span style= "White-space:pre" ></span>free (TMP); <span style= "White-space:pre" ></span>muntrace (); <span style= "White-space:pre" ></span>return 0;}
You can use Addr2line to view the address of the specific application and the Code of the Quartet address, and can help and analyze memory leaks;
3. Hook function
hook function Hook () to the memory line tracking;
4. Binutil Tools
Add2line:
AR: Archive file
As: Output assembly file,
LD: Connector
NM: List symbols for files
Objcopy:
Objdump: Displaying files
Ranlib: Generate archive file
Readelf: displaying elf file information
Size: Length of segment
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Fundamentals of Linux Programming