gpt4 book ai didi

c++ - Windows 上不会发生的 Linux 上的隐形 SIGSEGV?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:28:10 27 4
gpt4 key购买 nike

简介

我有一个 TCP/HTTP server that supports plugins以共享库的形式(DLL.so)。它有 make.sln 文件构建系统通过 premake .当我启动我的应用程序时,我向它提供一个这样的配置文件,其中描述了服务器应将哪些库用作插件以及它应传递给它们的参数。有一段时间我有 2 个插件并且都工作得很好。甚至现在如果我向我的服务器配置 fdiles 提供类似的东西也能正常工作 this .但是现在我有了正在开发的新插件,所以 new config file .

设置

在 Linux 上设置我的服务器所需的步骤非常简单

  • 下载构建脚本(从 here 描述 here )
  • ./cloud_server_net_setup.sh ,不需要 super 用户,需要 curl、make 和 g++在常规情况下(不是开发,这就足够了 - 它会得到提升,它需要的其他库到本地文件夹,它将构建所有这些,以发布形式构建服务器)
  • 现在你可以 cd 到 cloud_server/install-dir/
  • 调用 export LD_LIBRARY_PATH=./:./lib_boost
  • 并运行我们的服务器./CloudServer

但是我们需要调试版本所以在我们调用脚本之后我们

  • cd cloud_server/CloudServer/projects/linux-gmake/
  • 制作
  • cd bin/debug
  • export LD_LIBRARY_PATH=./:(我们调用脚本的地方)/cloud_server/install-dir/lib_boost

问题

  • 现在,我们终于可以调用 gdb 了。

所以我们这样调用它。这就是我们所看到的:

 gdb ./CloudServer

GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/ole_jak/cloud_server/CloudServer/projects/linux-gmake/bin/debug/CloudServer...done.
(gdb) r
Starting program: /home/ole_jak/cloud_server/CloudServer/projects/linux-gmake/bin/debug/CloudServer
[Thread debugging using libthread_db enabled]
Cloud Server v0.5
Copyright (c) 2011 Cloud Forever. All rights reserved.

Type 'help' to see help messages.
Config file path: config.xml
[New Thread 0x7ffff5967700 (LWP 11516)]
[New Thread 0x7ffff5166700 (LWP 11517)]
[New Thread 0x7ffff4965700 (LWP 11518)]
[New Thread 0x7ffff4164700 (LWP 11519)]
[New Thread 0x7ffff3963700 (LWP 11520)]
[New Thread 0x7ffff3162700 (LWP 11521)]
[New Thread 0x7ffff2961700 (LWP 11522)]
[New Thread 0x7ffff2160700 (LWP 11523)]
[New Thread 0x7ffff195f700 (LWP 11524)]
[New Thread 0x7ffff115e700 (LWP 11525)]
[New Thread 0x7ffff095d700 (LWP 11526)]
[New Thread 0x7fffebfff700 (LWP 11527)]
[New Thread 0x7fffeb7fe700 (LWP 11528)]
[New Thread 0x7fffeaffd700 (LWP 11529)]
[New Thread 0x7fffea7fc700 (LWP 11530)]
[New Thread 0x7fffe9ffb700 (LWP 11531)]
Library libFileService.so opened.
[New Thread 0x7fffe953c700 (LWP 11532)]
Library libUsersFilesService.so opened.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) x/i $pc
0x0: Cannot access memory at address 0x0

我是 Linux nube,我从 wikipedia 知道的所有关于段错误的信息,但我还知道关于我的服务器和我正在创建的这项新服务的另一件事 - 它在 Windows 上编译和运行时完全没有错误(VS2008、2010 解决方案可以从相同的预制脚本创建)。

所以我想知道这 2 个文件中的方式和位置 .cpp.h我创建了一个错误,它不会在 Windows 上显示,但在 Linux 上显示得如此戏剧化?它是可修复的,还是新鲜的眼睛可见的?

更新:Valgrind 输出

ole_jak@dspproc:~/cloud_server/CloudServer/projects/linux-gmake/bin/debug$ valgrind ./CloudServer
==11682== Memcheck, a memory error detector
==11682== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==11682== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==11682== Command: ./CloudServer
==11682==
Cloud Server v0.5
Copyright (c) 2011 Cloud Forever. All rights reserved.

Type 'help' to see help messages.
Config file path: config.xml
Library libFileService.so opened.
Library libUsersFilesService.so opened.
==11682== Jump to the invalid address stated on the next line
==11682== at 0x0: ???
==11682== by 0x4D49BE: sqlite3_free (sqlite3.c:18155)
==11682== by 0x102242D5: sqlite3OsInit (sqlite3.c:14162)
==11682== by 0x1029EB28: sqlite3_initialize (sqlite3.c:107299)
==11682== by 0x102A159F: openDatabase (sqlite3.c:108909)
==11682== by 0x102A1B29: sqlite3_open (sqlite3.c:109156)
==11682== by 0x1021CAB0: sqlite3pp::database::connect(char const*) (sqlite3pp.cpp:89)
==11682== by 0x1021C6E3: sqlite3pp::database::database(char const*) (sqlite3pp.cpp:74)
==11682== by 0x1020DDDF: users_files_service::create_files_table(std::string) (users_files_service.cpp:171)
==11682== by 0x1020BAFC: users_files_service::apply_config(boost::shared_ptr<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > >) (users_files_service.cpp:38)
==11682== by 0x4B5432: server_utils::parse_config_services(boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> >) (server_utils.cpp:156)
==11682== by 0x4B6436: server_utils::parse_config(boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> >) (server_utils.cpp:208)
==11682== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==11682==
==11682==
==11682== Process terminating with default action of signal 11 (SIGSEGV)
==11682== Bad permissions for mapped region at address 0x0
==11682== at 0x0: ???
==11682== by 0x4D49BE: sqlite3_free (sqlite3.c:18155)
==11682== by 0x102242D5: sqlite3OsInit (sqlite3.c:14162)
==11682== by 0x1029EB28: sqlite3_initialize (sqlite3.c:107299)
==11682== by 0x102A159F: openDatabase (sqlite3.c:108909)
==11682== by 0x102A1B29: sqlite3_open (sqlite3.c:109156)
==11682== by 0x1021CAB0: sqlite3pp::database::connect(char const*) (sqlite3pp.cpp:89)
==11682== by 0x1021C6E3: sqlite3pp::database::database(char const*) (sqlite3pp.cpp:74)
==11682== by 0x1020DDDF: users_files_service::create_files_table(std::string) (users_files_service.cpp:171)
==11682== by 0x1020BAFC: users_files_service::apply_config(boost::shared_ptr<boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> > >) (users_files_service.cpp:38)
==11682== by 0x4B5432: server_utils::parse_config_services(boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> >) (server_utils.cpp:156)
==11682== by 0x4B6436: server_utils::parse_config(boost::property_tree::basic_ptree<std::string, std::string, std::less<std::string> >) (server_utils.cpp:208)
==11682==
==11682== HEAP SUMMARY:
==11682== in use at exit: 124,050 bytes in 1,083 blocks
==11682== total heap usage: 1,814 allocs, 731 frees, 183,517 bytes allocated
==11682==
==11682== LEAK SUMMARY:
==11682== definitely lost: 0 bytes in 0 blocks
==11682== indirectly lost: 0 bytes in 0 blocks
==11682== possibly lost: 46,248 bytes in 799 blocks
==11682== still reachable: 77,802 bytes in 284 blocks
==11682== suppressed: 0 bytes in 0 blocks
==11682== Rerun with --leak-check=full to see details of leaked memory
==11682==
==11682== For counts of detected and suppressed errors, rerun with: -v
==11682== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
Убито
ole_jak@dspproc:~/cloud_server/CloudServer/projects/linux-gmake/bin/debug$

最佳答案

这是一个讨厌的。我不确定确切的根本原因,但这似乎是一个与多线程相关的问题。问题的直接原因是 sqlite3Config.m.xSize 函数指针在错误发生的时间和地点为 NULL

这个指针应该在第一次 sqlite3_initialize() 时被初始化为指向一个正确的函数。被调用,这通常发生在您第一次打开 SQLite 数据库文件时。通过在 GDB 中设置断点和观察点,我能够验证指针是否已成功设置,但在出现段错误时其值为 NULL

这可能意味着两件事之一:

  • 新指针值未正确传播到所有线程。 SQLite3 应该是线程安全的,但是好吧,线程可能是讨厌的小 bug ......

  • 指针在初始化后会被重置。我认为这不太可能,因为 sqlite3Config 结构在初始化后通常不会被修改。

我执行了一个简单的测试,顺便说一句,它可以用作临时解决方法:我添加了对 sqite3_initialize() 的显式调用作为 main() 中的第一条语句,允许它在任何线程启动之前执行。结果,段错误消失了,我得到了一个针对您的服务器的 shell 提示,它指向两个备选方案中的第一个。请注意,这充其量只是一种解决方法,因为不应显式调用 sqite3_initialize()。问题的根本原因可能仍然存在,并以其他方式让自己知道 - 或者,更糟糕的是,它可能会以微妙但难以检测的方式破坏事物。

因为 SQLite3 是 supposed to be thread-safe (以及 sqlite3_initialize() 函数的源代码 似乎 在这方面是正确的),我不确定发生了什么。这可能是 sqlite3pp 包装器或线程启动方式的问题。

关于c++ - Windows 上不会发生的 Linux 上的隐形 SIGSEGV?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8019485/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com