c选项,c语言求解方程组。

gcc编译选项 -fpack-struct 致程序 core dump 原因及解决-C语言-asp.net教程-壹聚教程网gcc编译选项 -fpack-struct 致程序 core dump 原因及解决gcc的 “-fpack-struct” 编译选项导致程序产生 core dump 文件,本文我们来看看产生 core dump 文件的原因及解决办法。
最近team引入gcov来做代码分析。编译好的程序在Solaris上运行的好好的,结果在Linux上一运行就会产生core dump文件。这篇文章就介绍整个分析过程。
首先用gdb分析core文件,显示是strlen调用出了问题:
#0& 0x386f in __strlen_sse42 () from /lib64/libc.so.6
#1& 0xc57a in __gcov_init ()
#2& 0xc4b9 in _GLOBAL__I_65535_0_g_cmd_param () at source/rerun/aicent_ara_rerun.c:963
#3& 0xdc26 in __do_global_ctors_aux ()
#4& 0x3743 in _init ()
#5& 0x00007fff6d6b3ce8 in ?? ()
#6& 0xdb55 in __libc_csu_init ()
#7& 0xecb0 in __libc_start_main () from /lib64/libc.so.6
#8& 0x4449 in _start ()
由于我们使用的gcc是用安装包形式安装的,没有源码。所以就从github上找了相应版本的gcc源代码,希望能有所帮助。以下是__gcov_init函数的代码(htt:///gcc-mirror/gcc/blob/gcc-4_4_7-release/gcc/libgcov.c):
__gcov_init (struct gcov_info *info)
& if (!info-&version)
& if (gcov_version (info, info-&version, 0))
&&&&& const char *ptr = info-&
&&&&& gcov_unsigned_t crc32 = gcov_crc32;
&&&&& size_t filename_length =& strlen(info-&filename);
&&&&& /* Refresh the longest file name information */
&&&&& if (filename_length & gcov_max_filename)
&&&&&&& gcov_max_filename = filename_
&&&&& gcov_unsigned_t value = *ptr && 24;
&&&&& for (ix = 8; ix--; value &&= 1)
&&&&&&&&& gcov_unsigned_
&&&&&&&&& feedback = (value ^ crc32) & 0x ? 0x04c11db7 : 0;
&&&&&&&&& crc32 &&= 1;
&&&&&&&&& crc32 ^=
&&&&& while (*ptr++);
&&&&& gcov_crc32 = crc32;
&&&&& if (!gcov_list)
&&& atexit (gcov_exit);
&&&&& info-&next = gcov_
&&&&& gcov_list =
& info-&version = 0;
结合源代码和core文件可以看出,应该是&size_t filename_length = strlen(info-&filename);&这一行出了问题。再结合汇编程序:
(gdb) disassemble __strlen_sse42
Dump of assembler code for function __strlen_sse42:
&& 0x3860 &+0&:&&&& pxor&& %xmm1,%xmm1
&& 0x3864 &+4&:&&&& mov&&& %edi,%ecx
&& 0x3866 &+6&:&&&& mov&&& %rdi,%r8
&& 0x3869 &+9&:&&&& and&&& $0xfffffffffffffff0,%rdi
&& 0x386d &+13&:&&& xor&&& %edi,%ecx
=& 0x386f &+15&:&&& pcmpeqb (%rdi),%xmm1
是访问rdi寄存器出了问题,而rdi保存的应该是strlen的参数,也就是&info-&filename&。试着访问一下rdi寄存器保存的地址:
(gdb) i registers rdi
rdi&&&&&&&&&&& 0x57c4ac80
(gdb) x/16xb 0x57c4ac
0x57c4ac:&&&&&& Cannot access memory at address 0x57c4ac
可以看到rdi寄存器保存的地址的确是个无效的地址。
接下来,就要分析一下为什么传入__gcov_init的info结构体的filename是一个无效指针。首先看一下gcov_info结构体的定义(/gcc-mirror/gcc/blob/gcc-4_4_7-release/gcc/gcov-io.h):
/* Information about a single object file.& */
struct gcov_info
& gcov_unsigned_& /* expected version number */
& struct gcov_info *&& /* link to next, used by libgcov */
& gcov_unsigned_&&& /* uniquifying time stamp */
& const char *&&&& /* output file name */
& unsigned n_&&&& /* number of functions */
& const struct gcov_fn_info * /* table of functions */
& unsigned ctr_&&&&&&& /* mask of counters instrumented.& */
& struct gcov_ctr_info counts[0]; /* count data. The number of bits
&&&&&&&&&&&&&&&&&&&& set in the ctr_mask field
&&&&&&&&&&&&&&&&&&&& determines how big this array
&&&&&&&&&&&&&&&&&&&& is.& */
查看调用__gcov_init的_GLOBAL__I_65535_0_g_cmd_param函数的汇编代码:
(gdb) disassemble _GLOBAL__I_65535_0_g_cmd_param
Dump of assembler code for function _GLOBAL__I_65535_0_g_cmd_param:
&& 0xc4ab &+0&:&&&& push&& %rbp
&& 0xc4ac &+1&:&&&& mov&&& %rsp,%rbp
&& 0xc4af &+4&:&&&& mov&&& $0x78d4a0,%edi
&& 0xc4b4 &+9&:&&&& callq& 0x53c4c0 &__gcov_init&
&& 0xc4b9 &+14&:&&& leaveq
&& 0xc4ba &+15&:&&& retq
End of assembler dump.
可以看到传入__gcov_init的参数为0x78d4a0,也就是指向gcov_info结构体的地址,查看这个地址的内容:
(gdb) x/64xb 0x78d4a0
0x78d4a0:&&&&&& 0x52&&& 0x34&&& 0x30&&& 0x34&&& 0x00&&& 0x00&&& 0x00&&& 0x00
0x78d4a8:&&&&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0x82&&& 0xf0&&& 0xc7&&& 0xa5
0x78d4b0:&&&&&& 0x60&&& 0xc4&&& 0x57&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0x00
0x78d4b8:&&&&&& 0x0b&&& 0x00&&& 0x00&&& 0x00&&& 0xac&&& 0xc4&&& 0x57&&& 0x00
0x78d4c0:&&&&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0x01&&& 0x00&&& 0x00&&& 0x00
0x78d4c8:&&&&&& 0x39&&& 0x01&&& 0x00&&& 0x00&&& 0xc0&&& 0xa4&&& 0x47&&& 0x03
0x78d4d0:&&&&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0xe0&&& 0xd8&&& 0x53&&& 0x00
0x78d4d8:&&&&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0x00&&& 0x00
可以看到对应filename成员的值应该为0x57c4ac0000000b,的确是个无效地址。问题分析到这里,没了思路。后来,在gcc的bugzilla里找到这个问题:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43341,才搞清楚是&-fpack-struct=4&这个编译选项导致的。
我们使用的是64位Linux,默认编译生成的可执行文件是64位的。所以gcov_info的默认内存布局应该是(gcov_unsigned_t类型占4个字节,指针类型占8个字节):
Offset &&& 4 bytes &&& 4 bytes
0 &&& version &&& 填充成员
8 &&& next &&& next
16 &&& stamp &&& 填充成员
24 &&& filename &&& filename
& &&& & &&& &
当使用&-fpack-struct=4&这个编译选项后,gcov_info的内存布局变为:
Offset &&& 4 bytes &&& 4 bytes
0 &&& version &&& next
8 &&& next &&& stamp
16 &&& filename &&& filename
& &&& & &&& &
经过推算,filename成员的值应该为0x57c460,验证一下:
(gdb) p (char*)0x57c460
$1 = 0x57c460 &/home/.../.....gcda&
打印出的是正确的值。在Solaris上没问题的原因是因为64位Solaris默认编译出来的程序是32位的。
看了一下gcc网站对-fpack-struct的介绍(https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fpack-struct-2675),使用这个编译选项会导致ABI(Application Binary Interface)的改变,所以使用时一定要谨慎。 上一页: &&&&&下一页:相关内容
空之幻想淘宝助手编辑推荐
电脑壁纸相关专题一个求 PI =3.1415926的算法,求解,该怎么处理_使用qmake自动编译Qt程序,如何设置g++的编译选项_关于PRO*C获取索引名的有关问题,待__脚本百事通
稍等,加载中……
^_^请注意,有可能下面的2篇文章才是您想要的内容:
一个求 PI =3.1415926的算法,求解,该怎么处理
使用qmake自动编译Qt程序,如何设置g++的编译选项
关于PRO*C获取索引名的有关问题,待
一个求 PI =3.1415926的算法,求解,该怎么处理
一个求 PI =3.1415926的算法,求解#include &stdio.h&
#include &math.h&
int main ()
  int i,n,s;
   double k,y2;
  printf("输入切割次数:");
 scanf("%d",&n);
  i=0;//切割次数
  k=3.0; //初始值
  y2=1.0; //内接六边形的边长
  s=6;//初始内接多边形的边数
while(i&=n)
  printf("第%d次切割,为%d边,PI=%.24f\n",i,s,k*sqrt(y2));
  s*=2; //边数增加1倍
  y2=2-sqrt(4-y2); //弦长
  k*=2.0;
//输入15以内的切割,结果好像是正确的,但是 
//y2=2-sqrt(4-y2); //弦长  让人无法理解,我画了一个图总感觉不对,求指点。。。
------解决方案--------------------内接六边形的边长是y,而不是y2 。
下面程序里的y2是y的平方的意思。
外切圆的半径是1 。
y^2(这个y是切割后的多边形的边长) = 2 - squr(4-y^2(这个y是切割前的多边形的边长))
K * =2;(多边形的边增加了1倍)
PI= K * sqrt(y^2);
你再画一个图看就好理解了。------解决方案--------------------我的回复怎么不见了。
y是正多边形的一条边长。
y^2 = 2 - sqrt(4 - y^2);
依据勾股定理,用上一次的y值和半径值(r为1)经过计算得到本次的y值。
使用qmake自动编译Qt程序,如何设置g++的编译选项
求助:使用qmake自动编译Qt程序,怎么设置g++的编译选项?用qmake自动生成makefile,再用make编译Qt程序时,g++的编译选项大概是这么多...:
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN ...
我希望在我的Qt程序中使用一些C++0x的特性,这需要在g++的编译选项中加入这两个:-std=c++0x -USTRICT_ANSI
即,变成:
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -std=c++0x -USTRICT_ANSI
高手们...请问应该怎样做呢?
------解决方案--------------------.pro 文件 QMAKE_CXXFLAGS
This variable contains the C++ compiler flags that are used when building a project. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified. The flags specific to debug and release modes can be adjusted by modifying the QMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE variables, respectively.------解决方案--------------------.pro中添一句:
QMAKE_CXXFLAGS += -std=c++0x -USTRICT_ANSI
关于PRO*C获取索引名的有关问题,待
关于PRO*C获取索引名的问题,急!!!在线等待!我的PC代码如下:
CDBOracle::getindexs(char*
tablename)
i=0;i &n_i++)
memset(r_ExistIndex[i],0,60);
sprintf((char
*)dynstmtsql,
INDEX_NAME
R_INDEXNAME
USER_IND_COLUMNS
TABLE_NAME
'%s ' ",tablename);
(int)sqlca.sqlerrd[2];
r_ExistIndex[i][59]=0;
trimSpace(r_ExistIndex[i]);
其代码就是将某表的索引名称保存在ExistIndex中,其中SQL语句在PLSQL中运行没有问题,而且换过select
index_name
user_indexes
table_name
=效果相同,出来的结果有两个错误
-2108ORA--2108:
product=RDBMS;
facility=ORA
2为ora-24337:未准备语句句柄
请大虾们帮我看一下。在线等待,谢谢。 ------解决方案--------------------r_ExistIndex怎么声明的?
请贴出代码
还有,lz确定程序连接上数据库了?
------解决方案--------------------看不出什么,建议在每个步骤之间加入调试信息进行调试
如果您想提高自己的技术水平,欢迎加入本站官方1号QQ群:&&,&&2号QQ群:,在群里结识技术精英和交流技术^_^
本站联系邮箱:当前位置:
>>> 完形填空: 从每小题A、B、C三个选项中,选出能填入空白处的最佳..
完形填空: 从每小题A、B、C三个选项中,选出能填入空白处的最佳答案。Some people say they have a solution(解决) to the problems of car crowding and pollution. In many cities, hundreds of people &&1&&bikes to work every day. In the New York City, some bike riders have even set up a group: Bike for a Better City. They say if more people ride bikes to work, there would be &&2&&cars and less dirty air.For several years this group has tried to gather(聚集) help for bike riders. They want to have special roads &&3&&bikes only, because when bikes and cars use the same road, there may be accidents. Bike for a Better City thinks if there were bike roads, more people would use bikes.But no bike roads have been established(建立) &&4&. Not everyone thinks it is a good &&5&. Drivers don’t like it, and some shop owners(主人) don’t like it, &&6&. And most people live &&7&&&far from the city to travel by bike. Still, people have done& 8&&about it. On Saturdays and Sundays, the largest open park in New York is &&9&&to cars, and the roads may be used by bikes only, but the group still says this is not enough and goes on fighting &&10&&bike roads. I think there will be more bike roads in the future.小题1:A. on&&&&&&&&&&&&& B. ride&&&&&&&&&&&& C. by&小题2:A. fewer&&&&&&&&&& B. less&&&&&&&&&&&& C. more小题3:A. until&&&&&&&&&& B. for&&&&&&&&&&&&& C. of小题4:A. yet&&&&&&&&&&&& B. once &&&&&&&&&&& C. just小题5:A. hope&&&&&&&&&&& B. way&&&&&&&&&&&&& C. help小题6:A. too&&&&&&&&&&&& B. also&&&&&&&&&&& C. either小题7:A. very&&&&&&&&&& B. quite&&&&&&&&&&& C. too小题8:A. nothing&&&&&&& B. something&&&&&&& C. anything小题9:A. closed&&&&&&&&& B. open&&&&&&&&&&& C. opening小题10:A. get&&&&&&&&&&& B. to get&&&&&&&&&& C. ask
题型:阅读理解难度:中档来源:不详
小题1:B小题2:A小题3:B小题4:A小题5:B小题6:C小题7:C小题8:B小题9:A小题10:B试题分析:这篇文章讲述了由于汽车对环境有着很大的污染,现在人们已经有了解决这个问题的方法,越来越多的人们骑自行车去上班而且,人们也在努力争取建立自行车专用道路以减少交通事故。小题1:根据句意:在许多城市里,成千上万的人骑自行车去上班。ride bikes骑自行车 by 后面接名词单数形式。故选B小题2:A. fewer更少的,修饰可数名词& B. less较少的,修饰不可数名词&& C. more更多的&根据句意:将会有更少的汽车和更少的空气污染。故选A小题3:A. until到…为止& B. for为,为了& C. of关于 根据句意:他们想拥有自行车专用道路。故选B小题4:A. yet 然而&&& B. once 曾经&&&& C. just仅仅&根据句意:然而,还没有建立自行车专用道路。故选A小题5:A. hope希望&& B. way方法&&&&& C. help帮助&&根据句意:并不是每个人都认为那是一个好方法。故选B小题6:A. too也,用于句末&&& B. also也,用于句中&&&& C. either也,用于否定句&&根据句意:一些司机不喜欢,一些店主也不喜欢。故选C小题7:A. very非常 &&B. quite&&&很,相当&&& C. too也,太;句意:绝大多数的人住在离城市太远而不能骑自行车旅行。too …to 太…而不能,故选C小题8:A. nothing 什么也没有&& B. something一些事情& C. anything任何事情&&&根据句意:人们已经为它做了一些事情了。故选B小题9:A. closed关闭&&&&&&&& B. open 打开&&&&&&&&&&& C. opening开放&根据句意:纽约的大量开放公园不对汽车开放。故选A小题10:根据句意:继续努力去争取自行车道路。fight to do为…而努力。 故选B点评:对于初中的完型填空,重在理解上下文的意思,一般不会很难。首先花几分钟进行整体的阅读,弄清楚时间,人物及情节。不提倡看一个做一个,平时的学习中要注意多积累固定句型,考试时才能判断出相对应的知识点。
马上分享给同学
据魔方格专家权威分析,试题“ 完形填空: 从每小题A、B、C三个选项中,选出能填入空白处的最佳..”主要考查你对&&社会现象类阅读&&等考点的理解。关于这些考点的“档案”如下:
现在没空?点击收藏,以后再看。
因为篇幅有限,只列出部分考点,详细请访问。
社会现象类阅读
社会现象类阅读:这类文章通过写人记事来揭示文章的主题,显示其社会意义,一般采用顺序或倒叙来叙述。题目经常是一些细节问题。考查的方面可以是原因和其中引发的思考。阅读这类文章要理清思路。描述社会现象英语:安居工程 housing project for low-income families安居小区 a neighborhood for low-income families保障妇女就业权利to guarantee women’s right to employment补发拖欠的离退休人员统筹项目内的养老金 All back pension entitlements have been paid for the retired covered by the overall government plan.裁定保险赔偿 adjudication of benefits城镇居民最低生活保障 guarantee of subsistence allowances for urban residents城镇社会保障体系the social security system in urban areas城镇职工基本医疗保险制度the basic medical insurance system for urban employees大力推行个人助学信贷 Personal loans to finance education should be vigorously promoted.待业人员 job seekers待遇优厚的工作 a well-paid job单亲家庭 single parent family定向培训 training for specific posts独生子女 the only child对保障方案进行精算评估 Security programs should undergo actuarial review.对口扶贫 provide poverty alleviation aid to the designated sister regions福利分房 buy a benefit-oriented apartment from the organization one works with岗位培训 on-job training个人自愿计划 voluntary private plans工伤保险制度the on-job injury insurance system工资收入分配制度the wage and income distribution system关系国计民生的大事 matters vital to national well-being and the people’s livelihood关心和支持残疾人事业 Programs to help the physically and mentally challenged deserve our care and support.关心老龄人 care for senior citizens.国企下岗职工基本生活保障 guarantee of basic cost of living allowances for workers laid off from state-owned enterprises过温饱生活 live a life at a subsistent level合理调整就业结构to rationally readjust the employment structure后勤服务社会化 make logistic services independent in their operation基本养老金basic pensions计划生育责任制 responsibility system of family planning 加快住房分配货币化进程 capitalization process of housing distribution/allocation加强计划生育工作 further improve family planning加强舆论监督 ensure that the correct orientation is maintained in public opinion 家庭美德 family virtues 建立集体合同制度to establish a group contract system建立市场导向的就业机制to establish a market-oriented employment mechanism建立新型的劳动关系to establish a new type of labor relations教育程度 education received
发现相似题
与“ 完形填空: 从每小题A、B、C三个选项中,选出能填入空白处的最佳..”考查相似的试题有:
3208101466506504429028662232124495

我要回帖

更多关于 c语言求解方程组 的文章

 

随机推荐