0

在这里,我编写了最简单的程序来重现我在 mysqlpp::Connection::query() 中的崩溃:

#include <mysql++.h>

int main(int argc, char* argv[])
{
    mysqlpp::Connection conn(false);
    if (conn.connect("neutrino", "localhost", "root", "1"))
    {
        mysqlpp::Query query = conn.query("select 1;");
    }

    return 0;
}

这是我的 CMakeLists.txt:

cmake_minimum_required (VERSION 3.2)
project (mysqlpptest)

add_executable(mysqlpptest main.cpp)

target_include_directories(mysqlpptest
    PRIVATE
        /usr/include/mysql
        /usr/include/mysql++
)

target_link_libraries(mysqlpptest
        -lmysqlclient
        -lmysqlpp
)

一切都编译和链接得很好,但是 query() 因分段错误而崩溃。

数据库已创建,因此 connect() 返回 true。这里也是mysql终端测试:

glaz@glaz-linux:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 190
Server version: 5.6.25-0ubuntu0.15.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use neutrino;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,00 sec)

任何想法在哪里挖掘崩溃?

更新:调用堆栈是无用的,因为库没有调试信息:

?? ()
std::istreambuf_iterator<char, std::char_traits<char> > std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > >::_M_extract_int<unsigned short>(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, std::_Ios_Iostate&, unsigned short&) const ()
std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > >::do_get(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, std::_Ios_Iostate&, unsigned short&) const ()
std::ostream::seekp(long, std::_Ios_Seekdir) ()
mysqlpp::Query::Query(mysqlpp::Connection*, bool, char const*) ()
mysqlpp::Connection::query(char const*) ()
main (argc=1, argv=0x7fffffffded8)
4

1 回答 1

1

我在发生崩溃的系统上将 g++ 从 4.9.2 更新到了 5.1.1。并且由于某种原因,后来编译器编译的代码与mysql库不兼容(显然是由4.9.2编译器编译的)。我将编译器恢复到 4.9.2(最初是 ubuntu 15.04 附带的),一切都变得正常了。

于 2015-10-02T15:30:42.967 回答