2011-03-13 11 views
10

मेरा प्रोग्राम स्थिर रूप से dietlibc के साथ संकलित है। यह उबंटू x64 पर संकलित है (x32 ध्वज का उपयोग कर x86 के लिए संकलित) और एक सेंटीस x86 पर चलाया जाता है।जीडीबी अजीब बैकट्रैक

संकलित आकार केवल 100 केबी है। मैं इसे -ggdb3 और कोई ऑप्टिमाइज़ेशन झंडे के साथ संकलित करता हूं।

मेरा प्रोग्राम सिग्सेजीवी सिग्नल को संभालने के लिए सिग्नल.h का उपयोग करता है और फिर abort() को कॉल करता है।

कार्यक्रम दिन के लिए समस्याओं के बिना चलता है लेकिन कभी-कभी segfaults।

 
[email protected]:~/Desktop$ gdb -c core.28569 program-name 
GNU gdb (GDB) 7.2 
Copyright (C) 2010 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later 
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 "--host=x86_64-linux-gnu --target=i386-linux-gnu". 
For bug reporting instructions, please see: 
... 
Reading symbols from program-name...done. 
[New Thread 28569] 
Core was generated by `program-name'. 
Program terminated with signal 6, Aborted. 
#0 0x00914410 in __kernel_vsyscall() 
Setting up the environment for debugging gdb. 
Function "internal_error" not defined. 
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal] 
Function "info_command" not defined. 
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal] 
.gdbinit:8: Error in sourced command file: 
Argument required (one or more breakpoint numbers). 
(gdb) bt 
#0 0x00914410 in __kernel_vsyscall() 
During symbol reading, incomplete CFI data; unspecified registers (e.g., eax) at 0x914411. 
#1 0x0804d7f4 in __unified_syscall() 
#2 0xbf8966c0 in ??() 
#3 
#4 0x2054454e in ??() 
#5 0x20524c43 in ??() 
#6 0x2e352e33 in ??() 
#7 0x32373033 in ??() 
#8 0x2e203b39 in ??() 
#9 0x2054454e in ??() 
#10 0x20524c43 in ??() 
#11 0x2e302e33 in ??() 
#12 0x32373033 in ??() 
#13 0x4d203b39 in ??() 
#14 0x61696465 in ??() 
#15 0x6e654320 in ??() 
#16 0x20726574 in ??() 
#17 0x36204350 in ??() 
#18 0x203b302e in ??() 
#19 0x54454e2e in ??() 
#20 0x43302e34 in ??() 
#21 0x00000029 in ??() 
#22 0xbf8989a8 in ??() 
Backtrace stopped: previous frame inner to this frame (corrupt stack?) 
(gdb) bt full 
#0 0x00914410 in __kernel_vsyscall() 
No symbol table info available. 
#1 0x0804d7f4 in __unified_syscall() 
No symbol table info available. 
#2 0xbf8966c0 in ??() 
No symbol table info available. 
#3 
No symbol table info available. 
#4 0x2054454e in ??() 
No symbol table info available. 
#5 0x20524c43 in ??() 
No symbol table info available. 
#6 0x2e352e33 in ??() 
No symbol table info available. 
#7 0x32373033 in ??() 
No symbol table info available. 
#8 0x2e203b39 in ??() 
No symbol table info available. 
#9 0x2054454e in ??() 
No symbol table info available. 
#10 0x20524c43 in ??() 
No symbol table info available. 
#11 0x2e302e33 in ??() 
No symbol table info available. 
#12 0x32373033 in ??() 
No symbol table info available. 
#13 0x4d203b39 in ??() 
No symbol table info available. 
#14 0x61696465 in ??() 
No symbol table info available. 
#15 0x6e654320 in ??() 
No symbol table info available. 
#16 0x20726574 in ??() 
No symbol table info available. 
#17 0x36204350 in ??() 
No symbol table info available. 
#18 0x203b302e in ??() 
No symbol table info available. 
#19 0x54454e2e in ??() 
No symbol table info available. 
#20 0x43302e34 in ??() 
No symbol table info available. 
#21 0x00000029 in ??() 
No symbol table info available. 
#22 0xbf8989a8 in ??() 
No symbol table info available. 
Backtrace stopped: previous frame inner to this frame (corrupt stack?) 
(gdb) quit 

उत्तर

16

यह एक ढेर लंघन: यह जब मैं अजीब बैकट्रैस कि मुझे समझ नहीं आता मिलता है।

#4 0x2054454e in ??() 

कि पाठ की तरह दिखता है, "दस" या "नेट"

#5 0x20524c43 in ??() 

"RLC" या "CLR"

और इतने पर।

पते का इलाज करें जैसे कि वे टेक्स्ट थे - देखें कि क्या आप यह पहचान सकते हैं कि यह टेक्स्ट आपके स्टैक को ओवरराइट करता है।

+0

असल में, एरिक सही है। यह एक अनियमित चर पर एक strncat था। यही कारण है कि यह कभी-कभी segfaulted और अन्य बार यह नहीं किया था। बीटीडब्ल्यू, पाठ वास्तव में "नेट" और "सीएलआर" था। धन्यवाद। –

+0

यहां तक ​​कि उस मामले में, मेरा जवाब शायद * भी * सही है, और आप अगली बार जब आप निरस्त कॉल करते हैं, तो आप dietlibc को बेहतर ढंग से ठीक करेंगे। –

6

आपका स्टैक ट्रेस वास्तव में समझने के लिए बहुत आसान है:

  • आप SIGSEGV कहीं मिला,
  • आपका संकेत हैंडलर किया जो कुछ भी यह होता है, तो abort()
  • कौन सा जारी raise(2) सिस्टम कॉल को फोन करके बुलाया __unified_syscall()

कारण आप GDB में कोई स्टैक ट्रेस मिलता है कि

012,351 है
  • __unified_syscall विधानसभा में कार्यान्वित किया जाता है, और
  • फ्रेम सूचक का उपयोग नहीं करता है, और
  • उचित cfi निर्देशों से कैसे थकान मिटाने के वर्णन करने के लिए नहीं है।

मैं इसे आहार में एक बग मानता हूं, वास्तव में ठीक करने के लिए आसान है।

--- dietlibc-0.31/i386/unified.S.orig 2011-03-13 10:16:23.000000000 -0700 
+++ dietlibc-0.31/i386/unified.S 2011-03-13 10:21:32.000000000 -0700 
@@ -31,8 +31,14 @@ __unified_syscall: 
    movzbl %al, %eax 
.L1: 
    push %edi 
+  cfi_adjust_cfa_offset (4) 
+  cfi_rel_offset (edi, 0) 
    push %esi 
+  cfi_adjust_cfa_offset (4) 
+  cfi_rel_offset (esi, 0) 
    push %ebx 
+  cfi_adjust_cfa_offset (4) 
+  cfi_rel_offset (ebx, 0) 
    movl %esp,%edi 
    /* we use movl instead of pop because otherwise a signal would 
     destroy the stack frame and crash the program, although it 
@@ -61,8 +67,11 @@ __unified_syscall: 
#endif 
.Lnoerror: 
    pop %ebx 
+  cfi_adjust_cfa_offset (-4) 
    pop %esi 
+  cfi_adjust_cfa_offset (-4) 
    pop %edi 
+  cfi_adjust_cfa_offset (-4) 

/* here we go and "reuse" the return for weak-void functions */ 
#include "dietuglyweaks.h" 

आप dietlibc पुनर्निर्माण नहीं कर सकता है, या अगर पैच गलत है, तो आप अभी भी बेहतर स्टैक ट्रेस का विश्लेषण करने में सक्षम हो सकता है: अगर यह (untested) पैच यह तुम्हारे लिए ठीक करता है देखें। जहां तक ​​मैं कह सकता हूं, __unified_syscall%ebp को स्पर्श नहीं करता है। तो अगर आप ऐसा करके एक उचित स्टैक ट्रेस प्राप्त करने में सक्षम हो सकता है:

define xbt 
    set $xbp = (void **)$arg0 
    while 1 
    x/2a $xbp 
    set $xbp = (void **)$xbp[0] 
    end 
end 

xbt $ebp 

नोट: अगर xbt काम करता है, यह (है कि फ्रेम का उपयोग नहीं करता SIGSEGV संकेत फ्रेम के चारों ओर मातम में जाने की संभावना है फ्रेम सूचक या तो)। इसका परिणाम पूर्ण कचरा हो सकता है, या एक छोड़े गए फ्रेम या दो में (जो वास्तव में फ्रेम होंगे जहां SIGSEGV हुआ)।

तो आप वास्तव में dietlibc में उचित अनइंड डिस्क्रिप्टर प्राप्त करने से बहुत बेहतर हैं।