求助。。。。关于unix 动态链接库coredump的问题
小弟在unix下写动态链接库,仿照网上很多例子来写的,但是到最后总是出现coredump, 希望各位高手们帮小弟解决下这个问题。
/*****************explicit.c ******************/
#include<stdio.h>
#include<dlfcn.h>
int main(int argc,char* argv[])
{
int a = 10;
int b = 20;
int sum = 0;
int(*pSum)();
printf("a=[%d],b=[%d],sum=[%d]\n",a,b,sum);
void *pdlHandle;
char* pdlErr;
printf("open so......\n");
pdlHandle = dlopen("./lib/libtest.so",RTLD_LAZY);
if(!pdlHandle)
{
printf("open dynamic library failed\n");
}
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%s\n",pdlErr);
return 0;
}
printf("getting from so....\n");
pSum = (int(*)())dlsym(pdlHandle,"retResult");
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%sn", pdlErr);
dlclose(pdlHandle);
return 0;
}
printf("got it!\n");
sum = pSum(a,b);
printf("calling success.........\n");
printf("The sum of a and b is ==== [%d]\n",sum);
dlclose(pdlHandle);
return 0;
/*********************************************************************/
函数指针可能会有点问题,但是绝对不是真正的问题所在,因为我尝试过void类型的,也会coredump。
retResult函数原型很简单,就是输出一句话,返回一个a+b。
编译库的make_lib:
all:libtest.so
CC=cc -q64 -qcpluscmt -g
.c.o:
$(CC) -c -Kpic $<
build_command:
$(CC) -G $(OBJS) -o ./lib/$(DLL)
all_objs=test.o
libtest.so:$(all_objs)
make -f ./make_lib OBJS="$(all_objs)" DLL=$@ build_command
操作系统:AIX
错误信息如下:
a=[10],b=[20],sum=[0]
open so......
getting from so....
got it!
Illegal instruction(coredump);
在线等答复~~~~~也可以加我qq 251157654, 谢谢了!
/*****************explicit.c ******************/
#include<stdio.h>
#include<dlfcn.h>
int main(int argc,char* argv[])
{
int a = 10;
int b = 20;
int sum = 0;
int(*pSum)();
printf("a=[%d],b=[%d],sum=[%d]\n",a,b,sum);
void *pdlHandle;
char* pdlErr;
printf("open so......\n");
pdlHandle = dlopen("./lib/libtest.so",RTLD_LAZY);
if(!pdlHandle)
{
printf("open dynamic library failed\n");
}
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%s\n",pdlErr);
return 0;
}
printf("getting from so....\n");
pSum = (int(*)())dlsym(pdlHandle,"retResult");
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%sn", pdlErr);
dlclose(pdlHandle);
return 0;
}
printf("got it!\n");
sum = pSum(a,b);
printf("calling success.........\n");
printf("The sum of a and b is ==== [%d]\n",sum);
dlclose(pdlHandle);
return 0;
/*********************************************************************/
函数指针可能会有点问题,但是绝对不是真正的问题所在,因为我尝试过void类型的,也会coredump。
retResult函数原型很简单,就是输出一句话,返回一个a+b。
编译库的make_lib:
all:libtest.so
CC=cc -q64 -qcpluscmt -g
.c.o:
$(CC) -c -Kpic $<
build_command:
$(CC) -G $(OBJS) -o ./lib/$(DLL)
all_objs=test.o
libtest.so:$(all_objs)
make -f ./make_lib OBJS="$(all_objs)" DLL=$@ build_command
操作系统:AIX
错误信息如下:
a=[10],b=[20],sum=[0]
open so......
getting from so....
got it!
Illegal instruction(coredump);
在线等答复~~~~~也可以加我qq 251157654, 谢谢了!
...全文
相关推荐
浅析Linux下利用coredump技术追查进程崩溃原因
主要介绍了Linux下利用coredump技术追查进程崩溃原因,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
Unix系统中核心转储文件的分析方法
简介:Unix系统中的核心文件是程序异常崩溃时生成的转储文件,包含了内存状态、寄存器值和文件描述符等关键信息。分析这些文件需要使用调试器如GDB,通过一系列命令和步骤来查看崩溃信息、变量状态、内存内容、寄存器和动态链接库等。此外,结合其他工具和代码审查,可以更深入地理解问题,并可能重现问题以验证分析结果。
如何使用coredump
在一个程序崩溃时,它一般会在指定目录下生成一个core文件。core文件仅仅是一个内存映象(同时加上调试信息),主要是用来调试的。
深入学习unix
一份很好的学习资料,希望对大家有帮助
Unix环境下core dump 分析
unix环境下的crash core dump分析。


