在windows 下 系統核心態程序藍屏,會產生dump文件. 用戶級程序在設置後,程序崩潰也會產生dump文件.以方便開發者用windbg進行分析.
so,linux 系統也有一套這樣的東東----->Linux Core Dump
引用 文章 <Linux Core Dump> http://www.cnblogs.com/hazir/p/linxu_core_dump.html
的話:
當程序運行的過程中異常終止或崩潰,操作系統會將程序當時的內存狀態記錄下來,保存在一個文件中,這種行為就叫做Core Dump(中文有的翻譯成“核心轉儲”)。我們可以認為 core dump 是“內存快照”,但實際上,除了內存信息之外,還有些關鍵的程序運行狀態也會同時 dump 下來,例如寄存器信息(包括程序指針、棧指針等)、內存管理信息、其他處理器和操作系統狀態和信息。core dump 對於編程人員診斷和調試程序是非常有幫助的,因為對於有些程序錯誤是很難重現的,例如指針異常,而 core dump 文件可以再現程序出錯時的情景。
其實 <Linux Core Dump>介紹core dump 很詳細,唯一缺的就是設置 只能當前有效,重啟後失效.
重啟後的設置有所殘缺.
這兒就重點說下重啟生生效的設置 .
為什麼在 /proc/sys/kernel/core_pattern,
/proc/sys/kernel/core_uses_pid
以及 ulimit -c unlimited
中的設置會失敗.
Linux 內核提供了一種通過 /proc 文件系統,在運行時訪問內核內部數據結構、改變內核設置的機制。proc文件系統是一個偽文件系統,它只存在內存當中,而不占用外存空間。它以文件系統的方式為訪問系統內核數據的操作提供接口。 用戶和應用程序可以通過proc得到系統的信息,並可以改變內核的某些參數。由於系統的信息,如進程,是動態改變的,所以用戶或應用程序讀取proc文件時,proc文件系統是動態從系統內核讀出所需信息並提交的。下面列出的這些文件或子文件夾,並不是都是在你的系統中存在,這取決於你的內核配置和裝載的模塊。另外,在/proc下還有三個很重要的目錄:net,scsi和sys。 Sys目錄是可寫的,可以通過它來訪問或修改內核的參數,而net和scsi則依賴於內核配置。例如,如果系統不支持scsi,則scsi 目錄不存在。 除了以上介紹的這些,還有的是一些以數字命名的目錄,它們是進程目錄。系統中當前運行的每一個進程都有對應的一個目錄在/proc下,以進程的 PID號為目錄名,它們是讀取進程信息的接口。而self目錄則是讀取進程本身的信息接口,是一個link。
/proc --- 一個虛擬文件系統
/proc 文件系統是一種內核和內核模塊用來向進程(process) 發送信息的機制(所以叫做/proc)。這個偽文件系統讓你可以和內核內部數據結構進行交互,獲取 有關進程的有用信息,在運行中(on the fly) 改變設置(通過改變內核參數)。 與其他文件系統不同,/proc 存在於內存之中而不是硬盤上。如果你察看文件/proc/mounts (和mount 命令一樣列出所有已經加載的文件系統),你會看到其中 一行是這樣的:
grep proc /proc/mounts
/proc /proc proc rw 0 0
/proc 由內核控制,沒有承載/proc 的設備。因為/proc 主要存放由內核控制的狀態信息,所以大部分這些信息的邏輯位置位於內核控制的內存。對/proc 進行一次'ls -l' 可以看到大部分文件都是0 字節大的;不過察看這些文件的時候,確實可以看到一些信息。這怎麼可能?這是因為/proc 文件系統和其他常規的文件系統一樣把自己注冊到虛擬文件系統層(VFS) 了。然而,直到當VFS 調用它,請求文件、目錄的i-node 的時候,/proc 文件系統才根據內核中的信息建立相應的文件和目錄。
通過/proc 與內核交互
上面討論的大部分/proc 的文件是只讀的。而實際上/proc 文件系統通過/proc 中可讀寫的文件提供了對內核的交互機制。寫這些文件可以改變內核的狀態,因而要慎重改動這些文件。/proc/sys 目錄存放所有可讀寫的文件的目錄,可以被用於改變內核行為。
/proc/sys/kernel - 這個目錄包含反通用內核行為的信息。/proc/sys/kernel/{domainname, hostname} 存放著機器/網絡的域名和主機名。這些文件可以用於修改這些名字。
注意上面標紅的文字
ulimit
-c filesize #這兒大小是以kb為單位的
ulimit
-c unlimited
--->改為
永久設置, 修改/etc/security/limits.conf文件:
root@iZ233or8cn2Z:~# cat /etc/security/limits.conf # /etc/security/limits.conf # #Each line describes a limit for a user in the form: # #<domain> <type> <item> <value> # #Where: #<domain> can be: # - an user name # - a group name, with @group syntax # - the wildcard *, for default entry # - the wildcard %, can be also used with %group syntax, # for maxlogin limit # - NOTE: group and wildcard limits are not applied to root. # To apply a limit to the root user, <domain> must be # the literal username root. # #<type> can have the two values: # - "soft" for enforcing the soft limits # - "hard" for enforcing hard limits # #<item> can be one of the following: # - core - limits the core file size (KB) # - data - max data size (KB) # - fsize - maximum filesize (KB) # - memlock - max locked-in-memory address space (KB) # - nofile - max number of open files # - rss - max resident set size (KB) # - stack - max stack size (KB) # - cpu - max CPU time (MIN) # - nproc - max number of processes # - as - address space limit (KB) # - maxlogins - max number of logins for this user # - maxsyslogins - max number of logins on the system # - priority - the priority to run user process with # - locks - max number of file locks the user can hold # - sigpending - max number of pending signals # - msgqueue - max memory used by POSIX message queues (bytes) # - nice - max nice priority allowed to raise to values: [-20, 19] # - rtprio - max realtime priority # - chroot - change root to directory (Debian-specific) # #<domain> <type> <item> <value> # #* soft core 0 #root hard core 100000 #* hard rss 10000 #@student hard nproc 20 #@faculty soft nproc 20 #@faculty hard nproc 50 #ftp hard nproc 0 #ftp - chroot /ftp #@student - maxlogins 4 # End of file root soft core unlimited root@iZ233or8cn2Z:~#
根據上面的意思當設置為
"* soft core unlimited" 時是對所有用戶 生效,然而在debian下沒有生效.
改成"root soft unlimited" 時 root 用戶 能生效.這個問題一直沒想明白.
在服務器上一直使用,如果有cored ump之後自動拉起的機制,比較容易發生core文件堆滿磁盤的情況,需要注意。我采用的是一個進程名只會生效一個dump的辦法.
core文件的格式和路徑: 修改/proc/sys/kernel/core_pattern
echo '%e.core.%p' > /proc/sys/kernel/core_pattern
永久設置
/etc/sysctl.conf配置文件
最後添加一行:
kernel.core_pattern = /dump/core-%e
這樣一個進程名,只會有一個dump生產.
core文件是否帶pid: 修改/proc/sys/kernel/core_uses_pid
這個就省掉了,否則後面 dump文件太多...
前面有篇文章<linux 下cmake 編譯 ,調用,調試 poco 1.6.0 小記>
http://www.cnblogs.com/bleachli/p/4363485.html
中有提到過poco項目的編譯.
當已經有了so後.
root@iZ233or8cn2Z:~# ls -l /disk1/d1/evn/poco-1.6.0-all/lib/Linux/x86_64/ total 59588 lrwxrwxrwx 1 root root 16 Aug 4 17:02 libCppUnitd.so -> libCppUnitd.so.1 -rwxr-xr-x 1 root root 541402 Aug 4 17:02 libCppUnitd.so.1 lrwxrwxrwx 1 root root 15 Aug 4 17:02 libCppUnit.so -> libCppUnit.so.1 -rwxr-xr-x 1 root root 54992 Aug 4 17:02 libCppUnit.so.1 lrwxrwxrwx 1 root root 18 Aug 4 16:59 libPocoDatad.so -> libPocoDatad.so.30 -rwxr-xr-x 1 root root 15261261 Aug 4 16:59 libPocoDatad.so.30 lrwxrwxrwx 1 root root 17 Aug 4 17:00 libPocoData.so -> libPocoData.so.30 -rwxr-xr-x 1 root root 2678872 Aug 4 17:00 libPocoData.so.30 lrwxrwxrwx 1 root root 24 Aug 4 17:01 libPocoDataSQLited.so -> libPocoDataSQLited.so.30 -rwxr-xr-x 1 root root 4089825 Aug 4 17:01 libPocoDataSQLited.so.30 lrwxrwxrwx 1 root root 23 Aug 4 17:01 libPocoDataSQLite.so -> libPocoDataSQLite.so.30 -rwxr-xr-x 1 root root 1038456 Aug 4 17:01 libPocoDataSQLite.so.30 lrwxrwxrwx 1 root root 24 Aug 4 16:54 libPocoFoundationd.so -> libPocoFoundationd.so.30 -rwxr-xr-x 1 root root 11049923 Aug 4 16:54 libPocoFoundationd.so.30 lrwxrwxrwx 1 root root 23 Aug 4 16:55 libPocoFoundation.so -> libPocoFoundation.so.30 -rwxr-xr-x 1 root root 2017184 Aug 4 16:55 libPocoFoundation.so.30 lrwxrwxrwx 1 root root 18 Aug 4 16:56 libPocoJSONd.so -> libPocoJSONd.so.30 -rwxr-xr-x 1 root root 2529263 Aug 4 16:56 libPocoJSONd.so.30 lrwxrwxrwx 1 root root 17 Aug 4 16:56 libPocoJSON.so -> libPocoJSON.so.30 -rwxr-xr-x 1 root root 323344 Aug 4 16:56 libPocoJSON.so.30 lrwxrwxrwx 1 root root 21 Aug 4 17:01 libPocoMongoDBd.so -> libPocoMongoDBd.so.30 -rwxr-xr-x 1 root root 1526246 Aug 4 17:01 libPocoMongoDBd.so.30 lrwxrwxrwx 1 root root 20 Aug 4 17:01 libPocoMongoDB.so -> libPocoMongoDB.so.30 -rwxr-xr-x 1 root root 168208 Aug 4 17:01 libPocoMongoDB.so.30 lrwxrwxrwx 1 root root 17 Aug 4 16:57 libPocoNetd.so -> libPocoNetd.so.30 -rwxr-xr-x 1 root root 7813242 Aug 4 16:57 libPocoNetd.so.30 lrwxrwxrwx 1 root root 16 Aug 4 16:58 libPocoNet.so -> libPocoNet.so.30 -rwxr-xr-x 1 root root 1200376 Aug 4 16:58 libPocoNet.so.30 lrwxrwxrwx 1 root root 18 Aug 4 16:56 libPocoUtild.so -> libPocoUtild.so.30 -rwxr-xr-x 1 root root 3542555 Aug 4 16:56 libPocoUtild.so.30 lrwxrwxrwx 1 root root 17 Aug 4 16:57 libPocoUtil.so -> libPocoUtil.so.30 -rwxr-xr-x 1 root root 480208 Aug 4 16:57 libPocoUtil.so.30 lrwxrwxrwx 1 root root 17 Aug 4 16:55 libPocoXMLd.so -> libPocoXMLd.so.30 -rwxr-xr-x 1 root root 3151822 Aug 4 16:55 libPocoXMLd.so.30 lrwxrwxrwx 1 root root 16 Aug 4 16:56 libPocoXML.so -> libPocoXML.so.30 -rwxr-xr-x 1 root root 592408 Aug 4 16:56 libPocoXML.so.30 lrwxrwxrwx 1 root root 17 Aug 4 17:02 libPocoZipd.so -> libPocoZipd.so.30 -rwxr-xr-x 1 root root 2503316 Aug 4 17:02 libPocoZipd.so.30 lrwxrwxrwx 1 root root 16 Aug 4 17:02 libPocoZip.so -> libPocoZip.so.30 -rwxr-xr-x 1 root root 291688 Aug 4 17:02 libPocoZip.so.30
測試項目結構如下:
src中是TestTimeServer.cpp
// // TimeServer.cpp // // $Id: //poco/1.4/Net/samples/TimeServer/src/TimeServer.cpp#1 $ // // This sample demonstrates the TCPServer and ServerSocket classes. // // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // and Contributors. // // SPDX-License-Identifier: BSL-1.0 // #include "Poco/Net/TCPServer.h" #include "Poco/Net/TCPServerConnection.h" #include "Poco/Net/TCPServerConnectionFactory.h" #include "Poco/Net/TCPServerParams.h" #include "Poco/Net/StreamSocket.h" #include "Poco/Net/ServerSocket.h" #include "Poco/Timestamp.h" #include "Poco/DateTimeFormatter.h" #include "Poco/DateTimeFormat.h" #include "Poco/Exception.h" #include "Poco/Util/ServerApplication.h" #include "Poco/Util/Option.h" #include "Poco/Util/OptionSet.h" #include "Poco/Util/HelpFormatter.h" #include <iostream> using Poco::Net::ServerSocket; using Poco::Net::StreamSocket; using Poco::Net::TCPServerConnection; using Poco::Net::TCPServerConnectionFactory; using Poco::Net::TCPServer; using Poco::Timestamp; using Poco::DateTimeFormatter; using Poco::DateTimeFormat; using Poco::Util::ServerApplication; using Poco::Util::Application; using Poco::Util::Option; using Poco::Util::OptionSet; using Poco::Util::HelpFormatter; class TimeServerConnection: public TCPServerConnection /// This class handles all client connections. /// /// A string with the current date and time is sent back to the client. { public: TimeServerConnection(const StreamSocket& s, const std::string& format): TCPServerConnection(s), _format(format) { } void run() { Application& app = Application::instance(); app.logger().information("Request from " + this->socket().peerAddress().toString()); try { Timestamp now; std::string dt(DateTimeFormatter::format(now, _format)); dt.append("\r\n"); socket().sendBytes(dt.data(), (int) dt.length()); } catch (Poco::Exception& exc) { app.logger().log(exc); } } private: std::string _format; }; class TimeServerConnectionFactory: public TCPServerConnectionFactory /// A factory for TimeServerConnection. { public: TimeServerConnectionFactory(const std::string& format): _format(format) { } TCPServerConnection* createConnection(const StreamSocket& socket) { return new TimeServerConnection(socket, _format); } private: std::string _format; }; class TimeServer: public Poco::Util::ServerApplication /// The main application class. /// /// This class handles command-line arguments and /// configuration files. /// Start the TimeServer executable with the help /// option (/help on Windows, --help on Unix) for /// the available command line options. /// /// To use the sample configuration file (TimeServer.properties), /// copy the file to the directory where the TimeServer executable /// resides. If you start the debug version of the TimeServer /// (TimeServerd[.exe]), you must also create a copy of the configuration /// file named TimeServerd.properties. In the configuration file, you /// can specify the port on which the server is listening (default /// 9911) and the format of the date/time string sent back to the client. /// /// To test the TimeServer you can use any telnet client (telnet localhost 9911). { public: TimeServer(): _helpRequested(false) { } ~TimeServer() { } protected: void initialize(Application& self) { loadConfiguration(); // load default configuration files, if present ServerApplication::initialize(self); } void uninitialize() { ServerApplication::uninitialize(); } void defineOptions(OptionSet& options) { ServerApplication::defineOptions(options); options.addOption( Option("help", "h", "display help information on command line arguments") .required(false) .repeatable(false)); } void handleOption(const std::string& name, const std::string& value) { ServerApplication::handleOption(name, value); if (name == "help") _helpRequested = true; } void displayHelp() { HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("OPTIONS"); helpFormatter.setHeader("A server application that serves the current date and time."); helpFormatter.format(std::cout); } int main(const std::vector<std::string>& args) { if (_helpRequested) { displayHelp(); } else { //帶參數就在 TimeServer::main 中崩潰... int * pTest=NULL; *pTest=0x1234; // get parameters from configuration file unsigned short port = (unsigned short) config().getInt("TimeServer.port", 1234); std::string format(config().getString("TimeServer.format", DateTimeFormat::ISO8601_FORMAT)); // set-up a server socket ServerSocket svs(port); // set-up a TCPServer instance TCPServer srv(new TimeServerConnectionFactory(format), svs); // start the TCPServer srv.start(); // wait for CTRL-C or kill waitForTerminationRequest(); // Stop the TCPServer srv.stop(); } return Application::EXIT_OK; } private: bool _helpRequested; }; int main(int argc, char** argv) { if(argc==1)//不帶參數就在 main 中崩潰 { int * pTest=NULL; *pTest=0x1233; } TimeServer app; return app.run(argc, argv); }
注意上面已經說了:
if(argc==1)//不帶參數就在 main 中崩潰
{
int * pTest=NULL;
*pTest=0x1233;
}
//帶參數就在 TimeServer::main 中崩潰...
int * pTest=NULL;
*pTest=0x1234;
CMakeList.txt:
#定義最低版本. #cmake_minimum_required(VERSION 3.0.0) # set(SAMPLE_NAME "TimeServer") #SET(CMAKE_BUILE_TYPE Debug) #指定編譯類型 設置編譯類型debug 或者release。 debug 版會生成相關調試信息,可以使用GDB 進行 set(myExeSuffix "") if (CMAKE_BUILE_TYPE STREQUAL Debug) add_definitions( -D_DEBUG ) add_definitions(-DDEBUG) add_definitions("$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") set(myExeSuffix "d") set(SAMPLE_NAME "TimeServer${myExeSuffix}") #SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") MESSAGE(STATUS "my build is debug...") else() add_definitions("$ENV{CXXFLAGS} -O3 -Wall") #SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") MESSAGE(STATUS "my build is release...") endif () PROJECT(${SAMPLE_NAME}) #定義工程名稱 #ADD_SUBDIRECTORY(utility) #添加要編譯的子目錄 為工程主目錄下的存放源代碼的子目錄使用該命令,各子目錄出現的順序隨意。 # set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${path_root_dir}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${path_root_dir}/lib) # Windows DLLs are "runtime" for CMake. Output them to "bin" like the Visual Studio projects do. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "") #設置程序exe輸出位置 SET(EXECUTABLE_OUTPUT_PATH "") # set(LOCAL_SRCS "") # aux_source_directory 作用是發現一個目錄下所有的源代碼文件並將列表存儲在一個變量中,這個指令臨時被用來 # 自動構建源文件列表。因為目前cmake還不能自動發現新添加的源文件。 aux_source_directory(src LOCAL_SRCS) # 生成exe 名字為 ${SAMPLE_NAME} 的值 add_executable(${SAMPLE_NAME} ${LOCAL_SRCS} ) # 這個指令可以用來為target添加需要鏈接的共享庫 target_link_libraries( ${SAMPLE_NAME} PocoNet${myExeSuffix} PocoUtil${myExeSuffix} PocoJSON${myExeSuffix} PocoXML${myExeSuffix} PocoFoundation${myExeSuffix} libmyodbc5a.so)
root@iZ233or8cn2Z:/disk1/d1/evn/mytest# cmake . -- my build is release... -- The C compiler identification is GNU 4.7.2 -- The CXX compiler identification is GNU 4.7.2 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Warning (dev) in CMakeLists.txt: No cmake_minimum_required command is present. A line of code such as cmake_minimum_required(VERSION 3.3) should be added at the top of the file. The version specified may be lower if you wish to support older CMake versions for this project. For more information run "cmake --help-policy CMP0000". This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring done -- Generating done -- Build files have been written to: /disk1/d1/evn/mytest root@iZ233or8cn2Z:/disk1/d1/evn/mytest# make Scanning dependencies of target TimeServer [ 50%] Building CXX object CMakeFiles/TimeServer.dir/src/TestTimeServer.o [100%] Linking CXX executable TimeServer [100%] Built target TimeServer root@iZ233or8cn2Z:/disk1/d1/evn/mytest# ./TimeServer Segmentation fault (core dumped)
上面(core dumped) 代表已經生成了dump文件.
root@iZ233or8cn2Z:/disk1/d1/evn/mytest# ls -lh /dump -rw------- 1 root root 1.7M Aug 6 12:46 core-TimeServer
使用gdb 進行調試.
root@iZ233or8cn2Z:/disk1/d1/evn/mytest# gdb ./TimeServer /mydump/core-TimeServer GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 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 /disk1/d1/evn/mytest/TimeServer...(no debugging symbols found)...done. [New LWP 7117] warning: Can't read pathname for load map: Input/output error. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `./TimeServer'. Program terminated with signal 11, Segmentation fault. #0 0x0000000000403dd9 in main () (gdb) where #0 0x0000000000403dd9 in main () (gdb) info share From To Syms Read Shared Object Library 0x00007f184ce19cb0 0x00007f184ce8e83c Yes (*) /usr/local/lib/libPocoNet.so.30 0x00007f184cb5c9d0 0x00007f184cb8a838 Yes (*) /usr/local/lib/libPocoUtil.so.30 0x00007f184c8f88f0 0x00007f184c91b9ec Yes (*) /usr/local/lib/libPocoJSON.so.30 0x00007f184c67fb50 0x00007f184c6bc0bc Yes (*) /usr/local/lib/libPocoXML.so.30 0x00007f184c2fbcd0 0x00007f184c3dcc74 Yes (*) /usr/local/lib/libPocoFoundation.so.30 0x00007f184bc8b230 0x00007f184bd45c98 Yes /usr/local/lib/libmyodbc5a.so 0x00007f184b99c640 0x00007f184ba0071b Yes (*) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0x00007f184b6bdef0 0x00007f184b6fd6f8 Yes (*) /lib/x86_64-linux-gnu/libm.so.6 0x00007f184b4a6e70 0x00007f184b4b65d8 Yes (*) /lib/x86_64-linux-gnu/libgcc_s.so.1 0x00007f184b137b80 0x00007f184b24fc2c Yes (*) /lib/x86_64-linux-gnu/libc.so.6 0x00007f184af02690 0x00007f184af0dce8 Yes (*) /lib/x86_64-linux-gnu/libpthread.so.0 0x00007f184acf9de0 0x00007f184acfa8f8 Yes (*) /lib/x86_64-linux-gnu/libdl.so.2 0x00007f184aaf3190 0x00007f184aaf64f8 Yes (*) /lib/x86_64-linux-gnu/librt.so.1 0x00007f184a8dcdf0 0x00007f184a8eb1f4 Yes /usr/local/lib/libodbcinst.so.2 0x00007f184d0c7af0 0x00007f184d0dfc83 Yes (*) /lib64/ld-linux-x86-64.so.2 (*): Shared library is missing debugging information. (gdb)
注意上面標紅的 "(no debugging symbols found)" "(*): Shared library is missing debugging information."
程序沒有調試信息..加載的so 也沒有調試信息.
所以我們只能見
"
(gdb) where
#0 0x0000000000403dd9 in main ()
"
在這兒出錯,但具體原因不知.
我們再看看進入so 文件內容崩潰的結果呢!
root@iZ233or8cn2Z:/disk1/d1/evn/mytest# ./TimeServer 2 Aborted (core dumped) root@iZ233or8cn2Z:/disk1/d1/evn/mytest# gdb ./TimeServer /mydump/core-TimeServer GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 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 /disk1/d1/evn/mytest/TimeServer...(no debugging symbols found)...done. [New LWP 7787] warning: Can't read pathname for load map: Input/output error. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `./TimeServer 2'. Program terminated with signal 6, Aborted. #0 0x00007f0c4e389165 in raise () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) where #0 0x00007f0c4e389165 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007f0c4e38c3e0 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007f0c4f5a8da5 in Poco::SignalHandler::handleSignal(int) () from /usr/local/lib/libPocoFoundation.so.30 #3 <signal handler called> #4 0x0000000000403e58 in TimeServer::main(std::vector<std::string, std::allocator<std::string> > const&) () #5 0x00007f0c4fda6407 in Poco::Util::Application::run() () from /usr/local/lib/libPocoUtil.so.30 #6 0x0000000000403dbd in main () (gdb)
還是沒有找到具體原因.
root@iZ233or8cn2Z:/disk1/d1/evn/mytest# cmake -DCMAKE_BUILE_TYPE=Debug . -- my build is debug... -- The C compiler identification is GNU 4.7.2 -- The CXX compiler identification is GNU 4.7.2 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Warning (dev) in CMakeLists.txt: No cmake_minimum_required command is present. A line of code such as cmake_minimum_required(VERSION 3.3) should be added at the top of the file. The version specified may be lower if you wish to support older CMake versions for this project. For more information run "cmake --help-policy CMP0000". This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring done -- Generating done -- Build files have been written to: /disk1/d1/evn/mytest root@iZ233or8cn2Z:/disk1/d1/evn/mytest# make Scanning dependencies of target TimeServerd [ 50%] Building CXX object CMakeFiles/TimeServerd.dir/src/TestTimeServer.o [100%] Linking CXX executable TimeServerd [100%] Built target TimeServerd root@iZ233or8cn2Z:/disk1/d1/evn/mytest# ls CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt Makefile src TimeServerd TimeServer.progen TimeServer.properties root@iZ233or8cn2Z:/disk1/d1/evn/mytest# ./TimeServerd Segmentation fault (core dumped)
使用gdb查看
root@iZ233or8cn2Z:/disk1/d1/evn/mytest# gdb ./TimeServerd /mydump/core-TimeServerd GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 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 /disk1/d1/evn/mytest/TimeServerd...done. [New LWP 8398] warning: Can't read pathname for load map: Input/output error. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `./TimeServerd'. Program terminated with signal 11, Segmentation fault. #0 0x0000000000404aca in main (argc=1, argv=0x7fff018b4c98) at /disk1/d1/evn/mytest/src/TestTimeServer.cpp:207 207 *pTest=0x1233; (gdb) info share From To Syms Read Shared Object Library 0x00007fa8ef6c5000 0x00007fa8ef75213c Yes /usr/local/lib/libPocoNetd.so.30 0x00007fa8ef381680 0x00007fa8ef3bc2d4 Yes /usr/local/lib/libPocoUtild.so.30 0x00007fa8ef0bf260 0x00007fa8ef0ee748 Yes /usr/local/lib/libPocoJSONd.so.30 0x00007fa8eedec140 0x00007fa8eee43ff8 Yes /usr/local/lib/libPocoXMLd.so.30 0x00007fa8ee9c5750 0x00007fa8eeaed290 Yes /usr/local/lib/libPocoFoundationd.so.30 0x00007fa8ee297230 0x00007fa8ee351c98 Yes /usr/local/lib/libmyodbc5a.so 0x00007fa8edfa8640 0x00007fa8ee00c71b Yes (*) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 0x00007fa8edcc9ef0 0x00007fa8edd096f8 Yes (*) /lib/x86_64-linux-gnu/libm.so.6 0x00007fa8edab2e70 0x00007fa8edac25d8 Yes (*) /lib/x86_64-linux-gnu/libgcc_s.so.1 0x00007fa8ed743b80 0x00007fa8ed85bc2c Yes (*) /lib/x86_64-linux-gnu/libc.so.6 0x00007fa8ed50e690 0x00007fa8ed519ce8 Yes (*) /lib/x86_64-linux-gnu/libpthread.so.0 0x00007fa8ed305de0 0x00007fa8ed3068f8 Yes (*) /lib/x86_64-linux-gnu/libdl.so.2 0x00007fa8ed0ff190 0x00007fa8ed1024f8 Yes (*) /lib/x86_64-linux-gnu/librt.so.1 0x00007fa8ecee8df0 0x00007fa8ecef71f4 Yes /usr/local/lib/libodbcinst.so.2 0x00007fa8ef9a9af0 0x00007fa8ef9c1c83 Yes (*) /lib64/ld-linux-x86-64.so.2 (*): Shared library is missing debugging information. (gdb) where #0 0x0000000000404aca in main (argc=1, argv=0x7fff018b4c98) at /disk1/d1/evn/mytest/src/TestTimeServer.cpp:207 (gdb)
看上面 poco 的so文件也參加載調試信息了.
"(no debugging symbols found)" "(*): Shared library is missing debugging information."
這兩個錯誤已經不見了.
這個錯誤定位已直觀了.
再看看so中的錯誤呢
root@iZ233or8cn2Z:/disk1/d1/evn/mytest# ./TimeServerd 22 2 Segmentation fault (core dumped) root@iZ233or8cn2Z:/disk1/d1/evn/mytest# gdb ./TimeServerd /mydump/core-TimeServerd GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 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 /disk1/d1/evn/mytest/TimeServerd...done. [New LWP 11949] warning: Can't read pathname for load map: Input/output error. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `./TimeServerd 22 2'. Program terminated with signal 11, Segmentation fault. #0 0x000000000040588e in TimeServer::main (this=0x7ffed2e55cb0, args=...) at /disk1/d1/evn/mytest/src/TestTimeServer.cpp:178 178 *pTest=0x1234; (gdb) where #0 0x000000000040588e in TimeServer::main (this=0x7ffed2e55cb0, args=...) at /disk1/d1/evn/mytest/src/TestTimeServer.cpp:178 #1 0x00007f0212ccf02d in Poco::Util::Application::run (this=0x7ffed2e55cb0) at src/Application.cpp:329 #2 0x00007f0212ceb49c in Poco::Util::ServerApplication::run (this=0x7ffed2e55cb0) at src/ServerApplication.cpp:97 #3 0x00007f0212ceb5ea in Poco::Util::ServerApplication::run (this=0x7ffed2e55cb0, argc=3, argv=0x7ffed2e55e68) at src/ServerApplication.cpp:612 #4 0x0000000000404afd in main (argc=3, argv=0x7ffed2e55e68) at /disk1/d1/evn/mytest/src/TestTimeServer.cpp:211 (gdb)
已經能直觀的找到我們的錯誤了.
在linux 這種服務程序的開發中,有了日志輸出+core dump 對於一般的程序員來方可以節省很多查找錯誤的時間.
cmake 雖然簡單.但命令也是比較多的.
以下兩個文章供參考:
http://blog.csdn.net/dbzhang800/article/details/6314073
http://www.cnblogs.com/lidabo/p/3974305.html