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

2015-03-01 10:56:51 +08:00
 moxiaotiao

在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

已放弃 (核心已转储)

如何解决

18835 次点击
所在节点    问与答
14 条回复
way2exluren
2015-03-01 11:02:21 +08:00
……上代码…
把系统最好设置成英文…调试信息更好懂
moxiaotiao
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
2015-03-01 11:21:21 +08:00
可能是中文目录名的问题。移到一个纯英文的目录再试下。
way2exluren
2015-03-01 11:54:19 +08:00
我还以为是自己写代码报错…原来是程序运行…
提示信息是文件错误啊……格式问题…
9hills
2015-03-01 11:56:44 +08:00
core dump ,用gdb 看core呗
moxiaotiao
2015-03-01 19:21:35 +08:00
@way2exluren 是的,装了一个程序,读取的数据格式没问题,从官网下载的
moxiaotiao
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
2015-03-01 21:14:29 +08:00
@moxiaotiao 用bt看断点,然后看看变量
moxiaotiao
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
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
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
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
2015-03-02 01:09:47 +08:00
@moxiaotiao 是的,你先学习下 gdb 的简单使用吧,很快的。然后结合代码 debug 即可
marguerite
2015-03-02 01:40:19 +08:00
最难的就是转储核心啦,你都有转储得核心就很简单了啊:

gdb
core 你的转储文件
bt

没有调试符号就按提示装调试符号,xxx-debuginfo 什么的重跑上面步骤就可以了。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/173693

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX