Segmentation fault 에러

익명 사용자의 이미지

Segmentation fault 에러가 생겨서 gdb로 core파일을 디버깅해보았습니다.

'gdb 실행파일 core' 라고 입력하면 아래와 같이 나옵니다.

출력결과>
#0 0x8828ba5c in ?? ()

그리고 다시 'bt' 를 입력하면 함수를 호출된 순서대로 보여줍니다.

출력결과>
#0 0x8828ba5c in ?? ()
#1 0x827a9fd in PTCPSocketRead (this=0x86b1a00, buf=0x8abffa48, maxLen=4) at socket.cxx548
#2 0x8288c1a in PChannelReadBlock (this=0x86b1a00, buf=0x8abffa48, len=4) at ../common/pchannel.cxx252
#3 0x8087f6d in SignalConnectionOnReceivedData (this=0x86b20d8) at SignalConnection.cxx286
#4 0x8087973 in SignalConnectionMain (this=0x86b20d8) at SignalConnection.cxx116
#5 0x829a61d in PThreadPX_ThreadStart (arg=0x86b20d8) at tlibthrd.cxx782
#6 0x40021a20 in pthread_start_thread (arg=0x8abffc00) at manager.c274

확실한 이유는 모르겠고, 단지 Null 참조라고 짐작하고 있습니다.
왜 이런 현상이 생기는지 혹시 아시는분 안 계신가요 ?
Segmentation fault가 생기는 원인에 대해서는 많이 조사해보았지만
어떤식으로 해결해야 할지 막막하네요.
약간의 힌트라도 좋으니 제발 답변 부탁드립니다.

익명 사용자의 이미지


자세히는 모르겠지만 socket 관련 describtor가 -1이 아닌가
하네요. 보통 read함수에서 SIGSEGV가 날 가능성이 있는 곳은
두군데인데요 sd와 buff입니다.

이들 두 변수를 추적하심이 좋을듯 합니다.

익명 사용자의 이미지

답변 주셔서 정말정말 감사드립니다.
가르쳐 주신대로 sd와 buff의 값을 확인해 볼려구 하는데
확인하는 방법을 확실히 몰라서 또 요렇게 질문 올립니다.

gdb에서 "print 변수" 라고 입력하는게 아닐까 싶어
여러가지 변수의 값을 입력해 보았습니다.
그런데 fd는 -1보다 큰 값을 가지고 있었고 buf는 0x0 라고 나옵니다.

제가 사용한 방법이 맞는지 그리고 buf 값 때문에 생긴 문제라면 어떻게
해결을 해야하는지 궁금합니다.

익명 사용자의 이미지

; 출력결과>
; #0 0x8828ba5c in ?? ()
; #1 0x827a9fd in PTCPSocketRead (this=0x86b1a00, buf=0x8abffa48, maxLen=4) at socket.cxx548
; #2 0x8288c1a in PChannelReadBlock (this=0x86b1a00, buf=0x8abffa48, len=4) at ../common/pchannel.cxx252
; #3 0x8087f6d in SignalConnectionOnReceivedData (this=0x86b20d8) at SignalConnection.cxx286
; #4 0x8087973 in SignalConnectionMain (this=0x86b20d8) at SignalConnection.cxx116
; #5 0x829a61d in PThreadPX_ThreadStart (arg=0x86b20d8) at tlibthrd.cxx782
; #6 0x40021a20 in pthread_start_thread (arg=0x8abffc00) at manager.c274


여기에서 보면 'buf=0x00'이 아닌데요.
뭔가 착오가 있지는 않은지요.
만약 buf가 'NULL'이면 100% SIGSEGV를 받습니다.

프로그램에서 "socket.cxx548" printf같은 함수로 직접 확인을 하심이.
주의할점은 너무 많이 나올 가능성이 존재하므로
if(fd < 0 || buf == NULL) {
printf("Value Error line=%d, fd[%d], buf[%p]\n", __LINE__, fd, buf);
exit(1); // or return(-1);
}
이렇게 하여 어디에서 부터 잘못된 값이 전달되어 오는지
확인을 하시라는 이야기 입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.