Some one asked the following question of GDB mailing list.
Hi,
I was wondering how come the call to "call cos(.2)" returns the wrong
answer in:
#include "math.h"
double (*fcn)(double);
main()
{
double t;
fcn = cos;
t=cos(.2);
t=cos(-.2);
}
(gdb) call cos(.2)
$16 = 104
(gdb) call fcn(.2)
$17 = 0.98006657784124163
Thanks,
--
View this message in context: http://old.nabble.com/Why-%22call-cos%28.2%29%22-returns-garbage--tp26909516p26909516.html
Sent from the Gnu - gdb - General mailing list archive at Nabble.com.
Here is my analysis.
Hello,
Looks like 'gdb' is missing debug information about the function 'cos' ,
and the debugger implicitly assumes all the functions return an 'int' ,
if the function is not compiled in debug mode.
I derive my explanation from the following test case.
1. Create a function 'double test_cos(double)' and compile it in optimized mode with -O3 using gcc
"$gcc -c -O3 test1.c"
2. Complie the file containing the 'main' function in debug mode
"$gcc -g test.c test1.o -lm"
============[gdb a.out]====================
(gdb) list 0
1 #include "math.h"
2 #include "test1.h"
3 double (*fcn)(double);
4 main()
5 {
6 double t;
7 fcn = cos;
8 t=cos(.2);
9 t=cos(-.2);
10 test_cos(.2);
(gdb) call fcn(0.2)
$4 = 0.98006657784124163
(gdb) call cos(0.2)
$5 = -1073792992
(gdb) call test_cos(0.2)
$6 = -1073792992
=====================================
============[test1.h]=================
#ifndef _test_1_h
#define _test_1_h
double test_cos(double);
#endif
====================================
============[test1.c]==================
#include "math.h"
#include "test1.h"
double test_cos(double a){
return cos(a);
}
====================================
============[test.c]==================
#include "math.h"
#include "test1.h"
double (*fcn)(double);
main()
{
double t;
fcn = cos;
t=cos(.2);
t=cos(-.2);
test_cos(.2);
}
===================================
May be the developers of gdb can you more details.
also
=======================================
(gdb) call cos
$6 = {text variable, no debug info} 0xc325d0 {cos}
=======================================

2 comments:
wabbit wabbit
免費聊天網免費視 訊聊天網免費處女免費視訊免費無馬免費無馬下載免費無瑪免費無碼情色免費無碼辣妹自衛免費紫薇免費紫薇命盤免費蒼井空免費電話故事免費飯島愛免費網上小說台灣ko聊天室kk視訊聊天kk視訊俱樂部kk視訊kk聊天俱樂部kk成人kk777視訊俱樂部kiss網站kiss電話下載kiss視訊kiss情色網kiss情色kiss情人網kiss情人色網kiss台灣情網色kiss台灣kissmmkiss911成人網kiss911成人kiss911comkiss711kiss520kiss168成人kiss168king7777netk9俱樂部j無碼jp素人露出大全集jp素人大全集
Post a Comment