Debug Linux Dynamic libraries (Dynamic library creation, invocation, debugging) __linux

Source: Internet
Author: User

Add is a function in the library LIB.C to generate liblib.so

GCC lib.c-shared-g-debug-o liblib.so

Compiles a program that invokes the library, specifying that the library file uses the current path

GCC Applib.c-o applib-wall-g liblib.so-wl,-rpath,./

To set a breakpoint on the dynamic library function add

(GDB) b add

Enter y in the prompt below

Function "Add" not defined.

Make breakpoint pending on future shared library load? (Y or [n]) y

Breakpoint 1 (Add) pending.

Execute program R

(GDB) R

The prompts are as follows:

Starting program:/home/zqk/work/webserver/applib

Breakpoint 1, add (a=2, b=3) at Lib.c:3

3 return a+b;

Then it goes into the function of the dynamic library.

Continue executing the program, enter C

(GDB) C

Continuing.

Rusult is 5

Program exited normally.

Here is the test program:

* LIB.C * *

int add (int a,int b)

{

return a+b;

}

* Lib.h * *

extern int Add (int a,int b);

* Applib * *

#include <stdio.h>

#include "Lib.h"

int main (void)

{

int a=2;

int b=3;

int result;

result = Add (a,b);

printf ("Rusult is%d/n", result);

return 0;

}

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.