且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

libyahoo分段故障

更新时间:2022-10-15 16:33:01


  

如何调试呢?


块引用>

执行以下命令:

 (GDB)打印yd->的client_id
(GDB)打印yss-> pager_port

我的猜测是,一个或两个以上的命令就会失败,因为 YD YSS 为NULL

如果是这样,问题的较早的在libyahoo2.c,它(显然)不检查错误,正确的。

的原因,你不能列表YAHOO_CALLBACK 是最有可能它是一个宏。看在 libyahoo2 / yahoo2_callbacks.h - 这是极有可能在那里定义

另外,你的链接命令行:

  gcc的-l yahoo2 y.c -o雅虎

完全是伪造的。正确的命令行应该是:

 的gcc -o y.c雅虎-lyahoo2

您可能需要阅读这个解释明白为什么的源代码和库顺序命令行的问题。

I wrote this code:

#include <libyahoo2/yahoo2.h>
#include <libyahoo2/yahoo2_callbacks.h>


int main() {
    int id ;
    char username[255] = "slam";
    char password[255] = "ss" ;
    id = yahoo_init(username, password);
    enum yahoo_status mYahoo ;
    mYahoo = YAHOO_STATUS_AVAILABLE ;
    yahoo_login(id , mYahoo );


    return 0;
}

Compile it, gcc -l yahoo2 y.c -o yahoo and run it with ./yahoo gives me a error: Segmentation fault

(gdb) run

Program received signal SIGSEGV, Segmentation fault.
0x001379b1 in yahoo_login (id=1, initial=0) at libyahoo2.c:1735

line 1735 code is:

tag = YAHOO_CALLBACK(ext_yahoo_connect_async) (yd->client_id,
        host, yss->pager_port, yahoo_connected, ccd, 0);

and see this :

(gdb) list YAHOO_CALLBACK
Function "YAHOO_CALLBACK" not defined.

How do I debug this?

How do I debug this?

Execute these commands:

(gdb) print yd->client_id
(gdb) print yss->pager_port

My guess would be that one or both of the above commands will fail, because yd or yss is NULL.

If so, the problem is earlier in libyahoo2.c, and it (apparently) doesn't check for errors properly.

The reason you can't list YAHOO_CALLBACK is most likely that it is a macro. Look in libyahoo2/yahoo2_callbacks.h -- it's very likely to be defined there.

Also, your link command line:

gcc -l yahoo2 y.c -o yahoo

is totally bogus. Correct command line should be:

gcc y.c -o yahoo -lyahoo2

You may want to read this explanation to understand why order of sources and libraries on command line matters.