GDB Debugging tools, dynamic loading, memory management (DAY04)

Source: Internet
Author: User
Tags mul

first, error handling in the program defines a global variable errno in the system. This global variable holds the information (error number) of the system call or the library function error. Then get the error message based on the error number. Example: Open a file, if the file does not exist, view the error message. Code See FILE.CPERROR (3) Strerror (3) #include<stdio.h>voidPerror (Const Char*s); function: output a system error message parameter: S: User given string. Return value: no return. Add: FILE*stdin; Standard input Keyboard file*stdout; Standard output Display file*stderr; Standard error output display # include<string.h>Char*strerror (interrnum) Function: Returns the description information corresponding to the error number parameter: Errnum: Specifies the error number return value: the error number corresponding to the error description information if the error number is not defined, return unknown error NNN. Ii. GDB Debugging Tools using the GCC gdb bash makefile How do I debug a program using the GDB debugging tool? 1, when compiling the linked program, add-g/-The ggdb parameter. The executable file that compiles the output contains debugging information. TMATH$LSADD.C mul.c point.c test.c t_math.htmath$gcc add.c mul.c test.c tmath$lsadd.c A. outmul.c point.c test.c t_math.htmath$ls-L A. out-rwxrwxr-x1Tarena Tarena7332August3  One: +A. outtmath$gcc add.c mul.c test.c-Gtmath$ls-L A. out-rwxrwxr-x1Tarena Tarena9580August3  One: -A. out2, use the GDB debugging tool to debug an executable file with debugging information, gdb a. outgdb debug Command L list List the name or line number of the program manifest B function Breakpoint Set breakpoint R run Execute program p variable name output variable value n Next next s step Step Q Quit DebuggingintA,b,c;a=b=c=3the parameter of the function. A variable of pointer type as a parameter to a function. Value-The result parameter. Example code see VALUE.C Three, dynamic loading in the program, according to the needs of the program to dynamically load a library function, this behavior is called dynamic loading. The system provides the following functions for dynamic loading: Dlopen (3) #include<dlfcn.h>void*dlopen (Const Char*filename,intflag); function: Loads a dynamic library file and returns an address parameter: FileName: Name of the file that specified the dynamic library Flag:rtld_lazy: Lazy load rtld_now: Load return value immediately: NULL failedChar*dlerror (void) Function: Gets the error generated by the Dlopen, Dlclose, dlsym functions. Parameters:voidreturn value: Returns a string. This string describes the cause of the error. void*dlsym (void*handle,Const Char*symbol): The address of the symbol loaded into memory in the memory lookup dynamic library. Parameters: Handle:dlopen (3) returns a value. Specifies the library function symbol to be manipulated: Specifies the symbol to find. Return value: NULL represents an error return symbol loaded into memory address. intDlclose (void*handle); function: Reduce the reference count of handle-related dynamic library files by 1. When the reference count of the library file is reduced to 0, the dynamic library is unloaded from memory. Remove parameter: Handle: Specifies the dynamic library to close. Is Dlopen (3) return value: not 0 error0Success Link with-LDL. Examples illustrate the use of dynamic loading. Load the libpmath.so dynamic library file into memory and use the functions in the library. Code See DYNAMIC.C IV. Memory Management register cache memory hard disk Cloud Page table page box virtual memory physical memory virtual address space Physical Address Demo segment Error SEGMENT.C Summary: First, error handling in the system errno Perro R (3) Strerror (3second, the use of GDB Debugging tools three, dynamic loading on-demand load Dlopen (3) Dlclose (3) Dlsym (3) Iv. Memory Management Basics Page Table page box physical memory virtual memory virtual address Physical address on the machine with the operating system, the CPU can see the virtual address

GDB Debugging tools, dynamic loading, memory management (DAY04)

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.