linux程式調試

來源:互聯網
上載者:User

strace -f -F -o strace.txt /data1/waf/sbin/nginx -c /data1/waf/conf/nginx.conf

如果想讓系統在訊號中斷造成的錯誤時產生core檔案, 我們需要在shell中按如下設定:
#設定core大小為無限
ulimit -c unlimited
#設定檔案大小為無限
ulimit unlimited
gdb /data1/waf/sbin/nginx core.21169

編譯nginx程式-g: 產生調試工具所用的偵錯符號資訊(如果所編譯的程式想要調試就需要加-g),-O, -O2,-O3: 最佳化編譯串連 是執行的更迅速 -O的最佳化<-O2的最佳化<-O3的最佳化(不加是預設是-O)這個只在你的程式已經確定沒有錯誤,發行就緒時才去進行最佳化 平時就不用了

設定Core Dump的核心轉儲檔案目錄和命名規則
/proc/sys/kernel/core_uses_pid可以控制產生的core檔案的檔案名稱中是否添加pid作為擴充,如果添加則檔案內容為1,否則為0
/proc/sys/kernel/core_pattern可以設定格式化的core檔案儲存位置或檔案名稱,比如原來檔案內容是core-%e
可以這樣修改:
echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
將會控制所產生的core檔案會存放到/corefile目錄下,產生的檔案名稱為core-命令名-pid-時間戳記
以下是參數列表:
    %p - insert pid into filename 添加pid
    %u - insert current uid into filename 添加當前uid
    %g - insert current gid into filename 添加當前gid
    %s - insert signal that caused the coredump into the filename 添加導致產生core的訊號
    %t - insert UNIX time that the coredump occurred into filename 添加core檔案產生時的unix時間
    %h - insert hostname where the coredump happened into filename 添加主機名稱
    %e - insert coredumping executable name into filename 添加命令名

測試產生core檔案:kill -s SIGSEGV $$

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.