《coredump问题原理探究》Linux x86版6.5节虚函数的coredump例子

在大型项目中,很容易出现版本不匹配的问题,其中导致的虚函数飘移的问题比较难解决。

 

在这里,用一个例子来说明如何解决这种问题。

建立三个源文件:testso.h,testso.cpp,xuzhina_dump_c6_s3_ex.cpp。

testso.h的代码如下:

 

  1	 #ifndef __TESTSO_H__
  2	 #define __TESTSO_H__
  3 
  4	 class xuzhina_dump_c6_s3_ex
  5	 {
  6	     public:
  7	         virtual char* encode( char* str );
  8	 };      
  9 
 10	 #endif

 

 

 

testso.cpp的代码如下:

  1	 #include <string.h>
  2	 #include "testso.h"
  3 
  4	 char* xuzhina_dump_c6_s3_ex::encode( char* str )
  5	 {
  6	     return str;
  7	 }
  8

 

xuzhina_dump_c6_s3_ex.cpp的代码如下:

 

  1	 #include <stdio.h>
  2	 #include "testso.h"
  3	 
  4	 int main()
  5	 {
  6	     char* hello = (char*)"hello";
  7	     xuzhina_dump_c6_s3_ex* test = new xuzhina_dump_c6_s3_ex;
  8	 
  9	     char* p = test->encode( hello );
 10 
 11	     printf( "the second char:%c\n", p[1] );
 12 
 13	     return 0;
 14	 }

更多内容请关注微信公众号“debugeeker", 链接为https://mp.weixin.qq.com/s/tunZvO_Btt5w1f4kWqm2Kw

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值