欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
讓程序崩潰時(shí)產(chǎn)生coredump

在 Windows 下我們已經(jīng)習慣了用 Windbg 之類(lèi)的工具調試 dump 文件,從而分析并排除程序運行時(shí)錯誤。在 Linux 下我們同樣可以完成類(lèi)似的工作 —— Core Dump。


我們先看看相關(guān)的設置。
$ ulimit -acore file size       (blocks, -c) 0data seg size        (kbytes, -d) unlimitedscheduling priority          (-e) 20file size            (blocks, -f) unlimitedpending signals              (-i) 16382max locked memory    (kbytes, -l) 64max memory size      (kbytes, -m) unlimitedopen files                   (-n) 1024pipe size         (512 bytes, -p) 8POSIX message queues  (bytes, -q) 819200real-time priority           (-r) 0stack size           (kbytes, -s) 8192cpu time            (seconds, -t) unlimitedmax user processes           (-u) unlimitedvirtual memory       (kbytes, -v) unlimitedfile locks                   (-x) unlimited

"core file size  (blocks, -c) 0" 意味著(zhù)在程序崩潰時(shí)不會(huì )生成 core dump 文件,我們需要修改一下設置。如果你和我一樣懶得修改配置文件,那么就輸入下面這樣命令吧。
$ sudo  sh -c "ulimit -c unlimited; ./test" # test 是可執行文件名。

等等…… 我們還是先準備個(gè)測試目標。
#include <stdio.h>#include <stdlib.h>void test(){    char* s = "abc";    *s = 'x';}int main(int argc, char** argv){    test();    return (EXIT_SUCCESS);}

很顯然,我們在 test() 里面寫(xiě)了一個(gè)不該寫(xiě)的東東,這無(wú)疑會(huì )很?chē)乐?。生成可執行文件后,執行上面的命令?/span>
$ sudo sh -c "ulimit -c unlimited; ./test"Segmentation fault (core dumped)
$ ls -ltotal 96-rw------- 1 root  root  167936 2010-01-06 13:30 core-rwxr-xr-x 1 yuhen yuhen   9166 2010-01-06 13:16 test

這個(gè) core 文件就是被系統 dump 出來(lái)的,我們分析目標就是它了。
$ sudo gdb test coreGNU gdb (GDB) 7.0-ubuntuCopyright (C) 2009 Free Software Foundation, Inc.Reading symbols from .../dist/Debug/test...done.warning: Can't read pathname for load map: Input/output error.Reading symbols from /lib/tls/i686/cmov/libpthread.so.0... ...done.(no debugging symbols found)...done.Loaded symbols for /lib/tls/i686/cmov/libpthread.so.0Reading symbols from /lib/tls/i686/cmov/libc.so.6... ...done.(no debugging symbols found)...done.Loaded symbols for /lib/tls/i686/cmov/libc.so.6Reading symbols from /lib/ld-linux.so.2... ...done.(no debugging symbols found)...done.Loaded symbols for /lib/ld-linux.so.2Core was generated by `./test'.Program terminated with signal 11, Segmentation fault.#0  0x080483f4 in test () at main.c:16warning: Source file is more recent than executable.16        *s = 'x';

最后這幾行提示已經(jīng)告訴我們錯誤的原因和代碼位置,接下來(lái)如何調試就是 gdb 的技巧了,可以先輸入 "where" 看看調用堆棧。
(gdb) where#0  0x080483f4 in test () at main.c:16#1  0x08048401 in main (argc=1, argv=0xbfd53e44) at main.c:22
(gdb) p s$1 = 0x80484d0 "abc"
(gdb) info filesSymbols from ".../dist/Debug/test".Local core dump file:Local exec file:    `.../dist/Debug/test', file type elf32-i386.    Entry point: 0x8048330    0x08048134 - 0x08048147 is .interp    ... ...    0x08048330 - 0x080484ac is .text    0x080484ac - 0x080484c8 is .fini    0x080484c8 - 0x080484d4 is .rodata

很顯然 "abc" 屬于 .rodata,嚴禁調戲。

----------------

附:如果你調試的是 Release (-O2) 版本,而且刪除(strip)了符號表,那還是老老實(shí)實(shí)數匯編代碼吧??梢?jiàn)用 Debug 版本試運行是很重要滴?。?!
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Linux下發(fā)生段錯誤時(shí)如何產(chǎn)生core文件
GDB調試core文件樣例(如何定位Segment fault)
linux下產(chǎn)生core文件以及不產(chǎn)生core文件的條件
Linux下的段錯誤產(chǎn)生的原因及調試方法
【精品博文】linux編程之 Core Dump
Core dump 介紹 - 熾翼鐵冰's Blog
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久