PDA

View Full Version : GDB and QT : Debugging woes



balasaravanan
3rd December 2010, 07:00
My Qt program crashes when executing a particular use case. When trying to debug, I encounter the following problem.

I am receiving a SIGSEGV when calling a function called addContacts which is found in the file ContactsForm.cpp.

But the GDB bedugger shows that the segfault is happening in this function addContacts but the file listed is c++/bits/char_traits.h.

I cannot understand why GDB is reporting an erraneous listing.


Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208564032 (LWP 21061)]
0x0807cb28 in ContactsForm::addContacts (this=0x91d1730)
at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/char_traits.h:258
258 { return strlen(__s); }
(gdb) bt
#0 0x0807cb28 in ContactsForm::addContacts (this=0x91d1730)
at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/char_traits.h:258
#1 0x0807d6e6 in ContactsForm::showEvent (this=0x91d1730, event=0xbfef98d0)
at Contacts/ContactsForm.cpp:38
#2 0x00566955 in QWidget::event (this=0x91d1730, event=0xbfef98d0)
at kernel/qwidget.cpp:8251

ChrisW67
3rd December 2010, 07:15
Looks awfully like you are passing a NULL or otherwise invalid pointer that ends up in the strlen function. Single step your code to see which line is triggering the death.

balasaravanan
3rd December 2010, 07:29
the problem is that after setting the break point to the addContacts functions, the debugger breaks . and then when i do next in gdb, it does not step through the code in my file (contactsForm.cpp). instead i see code listing of the std_traits.h . the listing that debugger gives when issuing an "l" command also returns code from the std_traits.h file.

JPNaude
3rd December 2010, 08:05
You should not do a next. You should step into the function and see what is happening.

balasaravanan
16th December 2010, 11:04
hi all

http://3.bp.blogspot.com/_MM287MrNX98/TQnjrFybsEI/AAAAAAAAB4U/CJZ4xFhxo6Q/s1600/gdb-e1.png


please find the attached png image for more idea on the problem

when setting a break point to the function showHoldLines, the breakpoint is set in the correct file.

while setting a break point to the function fn_1, the break point is set in the incorrect file.

i see this problem in most of the functions that use STL containers.

anybody knows what is happening.

thanks and regards.
B

jdiewald
16th December 2010, 17:21
The listing may, in fact, not be erroneous. The functions that you talk about are trivial, with little content. fn_1 doesn't actually do anything - it declares something that isn't used. The compiler may be inlining functions and simplifying the code because it can, even with little or no optimization turned on. Many compilers can and will do this even without the inline keyword. When this happens, the symbol information for the method that gets inlined can be lost - there's nothing left of "your" code. (This is actually a difficult problem for debugger writers - which I was many lifetimes ago.) In these cases, the debugger is showing the sources for the code that remains in the generated stream of instructions that implement your program.