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;
}