Fundamentals of Linux Programming

Source: Internet
Author: User

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

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.