简体   繁体   English

Linux / C ++如何调试发布应用程序

[英]Linux/C++ How to debug release application

I have linux c++ multithreaded application. 我有linux c ++多线程应用程序。 Now it's tested on production servers and have segfault. 现在它已在生产服务器上进行测试并具有段错误。 Problem is that I cannot reproduce that error on any of my test servers and have no access to production servers. 问题是我无法在任何测试服务器上重现该错误,也无法访问生产服务器。 I have no dump or any other useful information. 我没有转储或任何其他有用的信息。 Only line: segfault at 0000000046bf0fb8 rip 000000000048ac6b rsp 0000000046bf0fa0 error 6 只有行:segfault at 0000000046bf0fb8 rip 000000000048ac6b rsp 0000000046bf0fa0 error 6

I would like to ask community can I get from such line some information which will help decrease area of possible places where I should search. 我想问社区我可以从这条线路获得一些信息,这些信息将有助于减少我应该搜索的地方的区域。 I cannot run debug build on production because of its slow speed. 由于速度慢,我无法在生产上运行调试版本。 What can I add to release which help me debug? 我可以添加什么来帮助我调试? This bug looks like multithread bug, and hard to reproduce. 这个bug看起来像多线程的bug,很难重现。 But I'm not sure, because application works with a lot of different emails from MTA. 但我不确定,因为应用程序可以处理来自MTA的许多不同的电子邮件。

Platform: Linux 平台:Linux

Compiler line: g++ -O3 -D_REENTRANT 编译器行:g ++ -O3 -D_REENTRANT

Thank you. 谢谢。

upd.: Thanks for your answers. upd。:谢谢你的回答。 I can include debug information. 我可以包含调试信息。 I'd like to know base methods of debugging release builds. 我想知道调试发布版本的基本方法。 For example I have dump and release version. 例如,我有转储和发布版本。 How should I continue. 我该怎么办? What should I read about that? 我该怎么读? Can you explain in few words how you debug your application if possible? 您能用几句话解释如何调试应用程序吗? Thank you. 谢谢。

As Andy mentioned, leave the debugging symbols in when you make your release builds. 正如Andy所说,在发布版本时保留调试符号。

If this makes the size of the finished executable unacceptably large, then you can make a copy of the final executable and run it through strip to remove the debug symbols. 如果这使得完成的可执行文件的大小不可接受地大,那么您可以复制最终的可执行文件并通过strip运行它以删除调试符号。 This way you have two executables that are identical except one has debug symbols and the other does not. 这样你就有两个相同的可执行文件,除了一个有调试符号而另一个没有。 Put the one without symbols on the production server. 将没有符号的那个放在生产服务器上。 When it segfaults, debug against the copy of the executable that still contains debug symbols. 当它发生段错误时,请对仍包含调试符号的可执行文件的副本进行调试。

I've been reading the gdb manuals recently, and they recommend leaving the debugging symbols in eg g++ -g . 我最近一直在阅读gdb手册,他们建议将调试符号留在例如g++ -g

Since you don't have access to the production server maybe include some basic logging functionality that'll output a data to a text file. 由于您无权访问生产服务器,因此可能包含一些将数据输出到文本文件的基本日志记录功能。 You should be able to narrow down roughly where the error occurs, depending on which data has been output to your log file. 您应该能够大致缩小发生错误的位置,具体取决于哪些数据已输出到您的日志文件。

You can use gdb to get a backtrace of your program at the point where it segfaults even though you did not build your application with the debug flags. 即使您没有使用调试标志构建应用程序,也可以使用gdb在segfaults的位置获取程序的回溯。 This will at least give you an idea where your application segfaults. 这至少可以让您了解应用程序段错误的位置。

gdb <your_app_exe>
gdb> run
gdb> backtrace

or 要么

gdb <your_app_exe>
gdb> core-file <generated_core_file>

You can (and should) build release executables with debug information. 您可以(并且应该)使用调试信息构建版本可执行文件。 If you don't want to distribute executables containing the debug information, then you can separate the debug information and install it later for debugging. 如果您不想分发包含调试信息的可执行文件,则可以调试信息分开并稍后安装以进行调试。 That's what we do in our application. 这就是我们在申请中所做的事情。

well i found another solution, which im using very frequently, we normally get the stack (which we got in this case). 好吧,我发现了另一个解决方案,我非常频繁地使用,我们通常得到堆栈(在这种情况下我们得到)。

i have a executable which we deploy on some embedded platform. 我有一个可执行文件,我们部署在一些嵌入式平台上。 let say my executable is server. 假设我的可执行文件是服务器。 i use addr2line -e ./server and i paste the stack which i got from customer. 我使用addr2line -e ./server并粘贴我从客户那里得到的堆栈。 it will give u the details of line where problem occur. 它会告诉你问题发生的细节。

it might help you. 它可能会帮助你。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM