V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
moxiaotiao
V2EX  ›  问与答

在 UBUNTU 下调试程序出现段错误(核心已转储)如何解决

  •  
  •   moxiaotiao · 2015-03-01 10:56:51 +08:00 · 18799 次点击
    这是一个创建于 3555 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在UBUNTU下运行程序

    root@root-F81Se:$ flowcalc /trace/20010316.pcap.gz -e basic

    直接出现

    Opening trace file: Unable to guess format (/trace/20010316.pcap.gz)
    flowcalc.c:279 main(): Reading file '/trace/20010316.pcap.gz' failed

    已放弃 (核心已转储)

    如何解决

    14 条回复    2015-03-02 01:40:19 +08:00
    way2exluren
        1
    way2exluren  
       2015-03-01 11:02:21 +08:00 via Android
    ……上代码…
    把系统最好设置成英文…调试信息更好懂
    moxiaotiao
        2
    moxiaotiao  
    OP
       2015-03-01 11:14:39 +08:00
    @way2exluren
    root@root-F81Se:~/下载/flowcalc$ flowcalc /trace/20010316.pcap.gz -e basic
    %% flowcalc run at Sun Mar 1 10:43:47 2015
    % modules: basic

    @relation '/trace/20010316.pcap.gz'

    %% flowcalc 0.1
    % fc_id: flow id
    % fc_tstamp: timestamp of first packet in the flow
    % fc_duration: flow duration
    % fc_proto: transport protocol
    % fc_src_addr: IP address of connection initiator
    % fc_src_port: TP port number of connection initiator
    % fc_dst_addr: IP address of remote peer
    % fc_dst_port: TP port number of remote peer
    @attribute fc_id numeric
    @attribute fc_tstamp numeric
    @attribute fc_duration numeric
    @attribute fc_proto {TCP,UDP}
    @attribute fc_src_addr string
    @attribute fc_src_port numeric
    @attribute fc_dst_addr string
    @attribute fc_dst_port numeric

    %% basic_stats 0.1
    % bs_min_size_up: minimum payload size in forward direction
    % bs_avg_size_up: average payload size in forward direction
    % bs_max_size_up: maximum payload size in forward direction
    % bs_std_size_up: standard deviation of payload size in forward direction
    % bs_min_size_down: minimum payload size in backward direction
    % bs_avg_size_down: average payload size in backward direction
    % bs_max_size_down: maximum payload size in backward direction
    % bs_std_size_down: standard deviation of payload size in backward direction
    % bs_min_iat_up: minimum inter-arrival time in forward direction
    % bs_avg_iat_up: average inter-arrival time in forward direction
    % bs_max_iat_up: maximum inter-arrival time in forward direction
    % bs_std_iat_up: standard deviation of inter-arrival time in forward direction
    % bs_min_iat_down: minimum inter-arrival time in backward direction
    % bs_avg_iat_down: average inter-arrival time in backward direction
    % bs_max_iat_down: maximum inter-arrival time in backward direction
    % bs_std_iat_down: standard deviation of inter-arrival time in backward direction
    @attribute bs_min_size_up numeric
    @attribute bs_avg_size_up numeric
    @attribute bs_max_size_up numeric
    @attribute bs_std_size_up numeric
    @attribute bs_min_size_down numeric
    @attribute bs_avg_size_down numeric
    @attribute bs_max_size_down numeric
    @attribute bs_std_size_down numeric
    @attribute bs_min_iat_up numeric
    @attribute bs_avg_iat_up numeric
    @attribute bs_max_iat_up numeric
    @attribute bs_std_iat_up numeric
    @attribute bs_min_iat_down numeric
    @attribute bs_avg_iat_down numeric
    @attribute bs_max_iat_down numeric
    @attribute bs_std_iat_down numeric

    @data
    Opening trace file: Unable to guess format (/trace/20010316.pcap.gz)
    flowcalc.c:279 main(): Reading file '/trace/20010316.pcap.gz' failed

    已放弃 (核心已转储)
    halczy
        3
    halczy  
       2015-03-01 11:21:21 +08:00 via iPhone
    可能是中文目录名的问题。移到一个纯英文的目录再试下。
    way2exluren
        4
    way2exluren  
       2015-03-01 11:54:19 +08:00 via Android
    我还以为是自己写代码报错…原来是程序运行…
    提示信息是文件错误啊……格式问题…
    9hills
        5
    9hills  
       2015-03-01 11:56:44 +08:00
    core dump ,用gdb 看core呗
    moxiaotiao
        6
    moxiaotiao  
    OP
       2015-03-01 19:21:35 +08:00
    @way2exluren 是的,装了一个程序,读取的数据格式没问题,从官网下载的
    moxiaotiao
        7
    moxiaotiao  
    OP
       2015-03-01 20:30:20 +08:00
    @9hills

    GDB RESULT:

    warning: Can't read pathname for load map: 输入/输出错误.
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
    Core was generated by `flowcalc /home/maopengxin/trace/20010316.pcap.gz -e basic'.
    Program terminated with signal 6, Aborted.
    #0 0xb76fc424 in __kernel_vsyscall ()
    gdb()
    9hills
        8
    9hills  
       2015-03-01 21:14:29 +08:00 via iPad
    @moxiaotiao 用bt看断点,然后看看变量
    moxiaotiao
        9
    moxiaotiao  
    OP
       2015-03-01 21:47:25 +08:00
    @9hills

    (gdb) bt
    #0 0xb76fc424 in __kernel_vsyscall ()
    #1 0xb75521df in raise () from /lib/i386-linux-gnu/libc.so.6
    #2 0xb7555825 in abort () from /lib/i386-linux-gnu/libc.so.6
    #3 0xb76d7260 in _die (file=0x8049d1e "flowcalc.c", line=279,
    fn=0x804a2e9 "main", msg=0x804a2cf "Reading file '%s' failed\n")
    at lib.c:126
    #4 0x080497a0 in main ()
    9hills
        10
    9hills  
       2015-03-01 22:19:21 +08:00
    #3 0xb76d7260 in _die (file=0x8049d1e "flowcalc.c", line=279,
    fn=0x804a2e9 "main", msg=0x804a2cf "Reading file '%s' failed\n")
    at lib.c:126

    上面不是写了么,断点在 flowcalc.c的279行,先去看看行内是什么,然后print下相关变量debug
    moxiaotiao
        11
    moxiaotiao  
    OP
       2015-03-01 23:50:23 +08:00
    你好,279行的代码就是下面这个

    if (!lfc_run(fc->lfc, fc->file, fc->filter))
    die("Reading file '%s' failed\n", fc->file);
    moxiaotiao
        12
    moxiaotiao  
    OP
       2015-03-01 23:52:17 +08:00
    @9hills

    你好,279行的代码就是下面这个

    if (!lfc_run(fc->lfc, fc->file, fc->filter))
    die("Reading file '%s' failed\n", fc->file);

    你意思是GDB下面Print?
    9hills
        13
    9hills  
       2015-03-02 01:09:47 +08:00 via iPad
    @moxiaotiao 是的,你先学习下 gdb 的简单使用吧,很快的。然后结合代码 debug 即可
    marguerite
        14
    marguerite  
       2015-03-02 01:40:19 +08:00
    最难的就是转储核心啦,你都有转储得核心就很简单了啊:

    gdb
    core 你的转储文件
    bt

    没有调试符号就按提示装调试符号,xxx-debuginfo 什么的重跑上面步骤就可以了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2251 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 01:38 · PVG 09:38 · LAX 17:38 · JFK 20:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.