anakryiko / btfdump

BTF introspection tool
BSD 2-Clause "Simplified" License
28 stars 7 forks source link

thread 'main' panicked at 'index out of bounds #2

Closed cloudcomes closed 1 year ago

cloudcomes commented 2 years ago

cloudcome.net>/home/cloudcome/btfdump/target/debug/btf dump --format c test.o

thread 'main' panicked at 'index out of bounds: the len is 23 but the index is 23', src/types.rs:1538:46
stack backtrace:
   0:     0x55fd871dddcd - std::backtrace_rs::backtrace::libunwind::trace::h8217d0a8f3fd2f41
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55fd871dddcd - std::backtrace_rs::backtrace::trace_unsynchronized::h308103876b3af410
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55fd871dddcd - std::sys_common::backtrace::_print_fmt::hc208018c6153605e
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x55fd871dddcd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf89a7ed694dfb585
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x55fd871f9f9c - core::fmt::write::h21038c1382fe4264
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/fmt/mod.rs:1197:17
   5:     0x55fd871dba61 - std::io::Write::write_fmt::h7dbb1c9a3c254aef
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/io/mod.rs:1672:15
   6:     0x55fd871df455 - std::sys_common::backtrace::_print::h4e8889719c9ddeb8
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x55fd871df455 - std::sys_common::backtrace::print::h1506fe2cb3022667
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x55fd871df455 - std::panicking::default_hook::{{closure}}::hd9d7ce2a8a782440
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:295:22
   9:     0x55fd871df176 - std::panicking::default_hook::h5b16ec25444b1b5d
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:314:9
  10:     0x55fd871df9e6 - std::panicking::rust_panic_with_hook::hb0138cb6e6fea3e4
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:698:17
  11:     0x55fd871df8d7 - std::panicking::begin_panic_handler::{{closure}}::h4cb67095557cd1aa
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:588:13
  12:     0x55fd871de284 - std::sys_common::backtrace::__rust_end_short_backtrace::h2bfcac279dcdc911
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x55fd871df609 - rust_begin_unwind
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
  14:     0x55fd86e62de3 - core::panicking::panic_fmt::h1de71520faaa17d3
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
  15:     0x55fd86e62d22 - core::panicking::panic_bounds_check::hfef1f84c4a547e72
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:84:5
  16:     0x55fd86ea6c0d - btf::types::Btf::get_btf_str::h184e6d68284532fd
                               at /home/cloudcome/btfdump/src/types.rs:1538:46
  17:     0x55fd86ea4ad4 - btf::types::Btf::load_func_secs::hdd6266aee770e568
                               at /home/cloudcome/btfdump/src/types.rs:1413:23
  18:     0x55fd86ea05ee - btf::types::Btf::load::h5090202c0eed76fc
                               at /home/cloudcome/btfdump/src/types.rs:1105:33
  19:     0x55fd86e7b7cc - btf::main::h07c6070b1368d324
                               at /home/cloudcome/btfdump/src/main.rs:179:23
  20:     0x55fd86e67a2b - core::ops::function::FnOnce::call_once::habe98135a3ae8639
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
  21:     0x55fd86e83fce - std::sys_common::backtrace::__rust_begin_short_backtrace::h84e73ff9c9a78c0a
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys_common/backtrace.rs:122:18
  22:     0x55fd86e842d1 - std::rt::lang_start::{{closure}}::h800a4948425f75cc
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:145:18
  23:     0x55fd871d789e - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h4937aaa125c8d4b2
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:280:13
  24:     0x55fd871d789e - std::panicking::try::do_call::h6f5c70e8b0a34f92
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  25:     0x55fd871d789e - std::panicking::try::h68766ba264ecf2e2
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  26:     0x55fd871d789e - std::panic::catch_unwind::hc36033d2f9cc04af
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  27:     0x55fd871d789e - std::rt::lang_start_internal::{{closure}}::h78c037f4a1a28ded
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:128:48
  28:     0x55fd871d789e - std::panicking::try::do_call::he6e1fffda4c750ee
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:492:40
  29:     0x55fd871d789e - std::panicking::try::h48a77ddbb2f4c87a
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:456:19
  30:     0x55fd871d789e - std::panic::catch_unwind::hfa809b06a550a9e7
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panic.rs:137:14
  31:     0x55fd871d789e - std::rt::lang_start_internal::h4db69ed48eaca005
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:128:20
  32:     0x55fd86e842a0 - std::rt::lang_start::h197089584f4bf80f
                               at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/rt.rs:144:17
  33:     0x55fd86e830cc - main
  34:     0x7fa8502c3fd0 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  35:     0x7fa8502c407d - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:409:3
  36:     0x55fd86e63075 - _start
  37:                0x0 - <unknown>
anakryiko commented 2 years ago

@cloudcomes can you please share that test.o that causes crash?

cloudcomes commented 2 years ago

1 Here is src code:

cat test.c

struct A {
   int a;
   char b;
};

int test(struct A *t) {
    return t->a;
}

2 compile it to test.o

clang -O2 -Wall -g -target bpf -c test.c -o test.o

3 get s file clang -S -g -target bpf test.c

4 cat test.s

root@cloudcome:/home/cloudcome/ebpf/trace/btf# cat test.s
    .text
    .file   "test.c"
    .globl  test                            # -- Begin function test
    .p2align    3
    .type   test,@function
test:                                   # @test
.Lfunc_begin0:
    .file   1 "/home/cloudcome/ebpf/trace/btf" "test.c"
    .loc    1 6 0                           # test.c:6:0
    .cfi_sections .debug_frame
    .cfi_startproc
# %bb.0:
    *(u64 *)(r10 - 8) = r1
.Ltmp0:
    .loc    1 7 12 prologue_end             # test.c:7:12
.Ltmp1:
.Ltmp2:
    r1 = *(u64 *)(r10 - 8)
    .loc    1 7 5 is_stmt 0                 # test.c:7:5
.Ltmp3:
    r0 = *(u32 *)(r1 + 0)
    exit
.Ltmp4:
.Ltmp5:
.Lfunc_end0:
    .size   test, .Lfunc_end0-test
    .cfi_endproc
                                        # -- End function
    .section    .debug_abbrev,"",@progbits
    .byte   1                               # Abbreviation Code
    .byte   17                              # DW_TAG_compile_unit
    .byte   1                               # DW_CHILDREN_yes
    .byte   37                              # DW_AT_producer
    .byte   14                              # DW_FORM_strp
    .byte   19                              # DW_AT_language
    .byte   5                               # DW_FORM_data2
    .byte   3                               # DW_AT_name
    .byte   14                              # DW_FORM_strp
    .byte   16                              # DW_AT_stmt_list
    .byte   23                              # DW_FORM_sec_offset
    .byte   27                              # DW_AT_comp_dir
    .byte   14                              # DW_FORM_strp
    .byte   17                              # DW_AT_low_pc
    .byte   1                               # DW_FORM_addr
    .byte   18                              # DW_AT_high_pc
    .byte   6                               # DW_FORM_data4
    .byte   0                               # EOM(1)
    .byte   0                               # EOM(2)
    .byte   2                               # Abbreviation Code
    .byte   46                              # DW_TAG_subprogram
    .byte   1                               # DW_CHILDREN_yes
    .byte   17                              # DW_AT_low_pc
    .byte   1                               # DW_FORM_addr
    .byte   18                              # DW_AT_high_pc
    .byte   6                               # DW_FORM_data4
    .byte   64                              # DW_AT_frame_base
    .byte   24                              # DW_FORM_exprloc
    .byte   3                               # DW_AT_name
    .byte   14                              # DW_FORM_strp
    .byte   58                              # DW_AT_decl_file
    .byte   11                              # DW_FORM_data1
    .byte   59                              # DW_AT_decl_line
    .byte   11                              # DW_FORM_data1
    .byte   39                              # DW_AT_prototyped
    .byte   25                              # DW_FORM_flag_present
    .byte   73                              # DW_AT_type
    .byte   19                              # DW_FORM_ref4
    .byte   63                              # DW_AT_external
    .byte   25                              # DW_FORM_flag_present
    .byte   0                               # EOM(1)
    .byte   0                               # EOM(2)
    .byte   3                               # Abbreviation Code
    .byte   5                               # DW_TAG_formal_parameter
    .byte   0                               # DW_CHILDREN_no
    .byte   2                               # DW_AT_location
    .byte   24                              # DW_FORM_exprloc
    .byte   3                               # DW_AT_name
    .byte   14                              # DW_FORM_strp
    .byte   58                              # DW_AT_decl_file
    .byte   11                              # DW_FORM_data1
    .byte   59                              # DW_AT_decl_line
    .byte   11                              # DW_FORM_data1
    .byte   73                              # DW_AT_type
    .byte   19                              # DW_FORM_ref4
    .byte   0                               # EOM(1)
    .byte   0                               # EOM(2)
    .byte   4                               # Abbreviation Code
    .byte   36                              # DW_TAG_base_type
    .byte   0                               # DW_CHILDREN_no
    .byte   3                               # DW_AT_name
    .byte   14                              # DW_FORM_strp
    .byte   62                              # DW_AT_encoding
    .byte   11                              # DW_FORM_data1
    .byte   11                              # DW_AT_byte_size
    .byte   11                              # DW_FORM_data1
    .byte   0                               # EOM(1)
    .byte   0                               # EOM(2)
    .byte   5                               # Abbreviation Code
    .byte   15                              # DW_TAG_pointer_type
    .byte   0                               # DW_CHILDREN_no
    .byte   73                              # DW_AT_type
    .byte   19                              # DW_FORM_ref4
    .byte   0                               # EOM(1)
    .byte   0                               # EOM(2)
    .byte   6                               # Abbreviation Code
    .byte   19                              # DW_TAG_structure_type
    .byte   1                               # DW_CHILDREN_yes
    .byte   3                               # DW_AT_name
    .byte   14                              # DW_FORM_strp
    .byte   11                              # DW_AT_byte_size
    .byte   11                              # DW_FORM_data1
    .byte   58                              # DW_AT_decl_file
    .byte   11                              # DW_FORM_data1
    .byte   59                              # DW_AT_decl_line
    .byte   11                              # DW_FORM_data1
    .byte   0                               # EOM(1)
    .byte   0                               # EOM(2)
    .byte   7                               # Abbreviation Code
    .byte   13                              # DW_TAG_member
    .byte   0                               # DW_CHILDREN_no
    .byte   3                               # DW_AT_name
    .byte   14                              # DW_FORM_strp
    .byte   73                              # DW_AT_type
    .byte   19                              # DW_FORM_ref4
    .byte   58                              # DW_AT_decl_file
    .byte   11                              # DW_FORM_data1
    .byte   59                              # DW_AT_decl_line
    .byte   11                              # DW_FORM_data1
    .byte   56                              # DW_AT_data_member_location
    .byte   11                              # DW_FORM_data1
    .byte   0                               # EOM(1)
    .byte   0                               # EOM(2)
    .byte   0                               # EOM(3)
    .section    .debug_info,"",@progbits
.Lcu_begin0:
    .long   .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
.Ldebug_info_start0:
    .short  4                               # DWARF version number
    .long   .debug_abbrev                   # Offset Into Abbrev. Section
    .byte   8                               # Address Size (in bytes)
    .byte   1                               # Abbrev [1] 0xb:0x7c DW_TAG_compile_unit
    .long   .Linfo_string0                  # DW_AT_producer
    .short  12                              # DW_AT_language
    .long   .Linfo_string1                  # DW_AT_name
    .long   .Lline_table_start0             # DW_AT_stmt_list
    .long   .Linfo_string2                  # DW_AT_comp_dir
    .quad   .Lfunc_begin0                   # DW_AT_low_pc
    .long   .Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
    .byte   2                               # Abbrev [2] 0x2a:0x28 DW_TAG_subprogram
    .quad   .Lfunc_begin0                   # DW_AT_low_pc
    .long   .Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
    .byte   1                               # DW_AT_frame_base
    .byte   90
    .long   .Linfo_string3                  # DW_AT_name
    .byte   1                               # DW_AT_decl_file
    .byte   6                               # DW_AT_decl_line
                                        # DW_AT_prototyped
    .long   82                              # DW_AT_type
                                        # DW_AT_external
    .byte   3                               # Abbrev [3] 0x43:0xe DW_TAG_formal_parameter
    .byte   2                               # DW_AT_location
    .byte   145
    .byte   0
    .long   .Linfo_string5                  # DW_AT_name
    .byte   1                               # DW_AT_decl_file
    .byte   6                               # DW_AT_decl_line
    .long   89                              # DW_AT_type
    .byte   0                               # End Of Children Mark
    .byte   4                               # Abbrev [4] 0x52:0x7 DW_TAG_base_type
    .long   .Linfo_string4                  # DW_AT_name
    .byte   5                               # DW_AT_encoding
    .byte   4                               # DW_AT_byte_size
    .byte   5                               # Abbrev [5] 0x59:0x5 DW_TAG_pointer_type
    .long   94                              # DW_AT_type
    .byte   6                               # Abbrev [6] 0x5e:0x21 DW_TAG_structure_type
    .long   .Linfo_string9                  # DW_AT_name
    .byte   8                               # DW_AT_byte_size
    .byte   1                               # DW_AT_decl_file
    .byte   1                               # DW_AT_decl_line
    .byte   7                               # Abbrev [7] 0x66:0xc DW_TAG_member
    .long   .Linfo_string6                  # DW_AT_name
    .long   82                              # DW_AT_type
    .byte   1                               # DW_AT_decl_file
    .byte   2                               # DW_AT_decl_line
    .byte   0                               # DW_AT_data_member_location
    .byte   7                               # Abbrev [7] 0x72:0xc DW_TAG_member
    .long   .Linfo_string7                  # DW_AT_name
    .long   127                             # DW_AT_type
    .byte   1                               # DW_AT_decl_file
    .byte   3                               # DW_AT_decl_line
    .byte   4                               # DW_AT_data_member_location
    .byte   0                               # End Of Children Mark
    .byte   4                               # Abbrev [4] 0x7f:0x7 DW_TAG_base_type
    .long   .Linfo_string8                  # DW_AT_name
    .byte   6                               # DW_AT_encoding
    .byte   1                               # DW_AT_byte_size
    .byte   0                               # End Of Children Mark
.Ldebug_info_end0:
    .section    .debug_str,"MS",@progbits,1
.Linfo_string0:
    .asciz  "Ubuntu clang version 13.0.0-2" # string offset=0
.Linfo_string1:
    .asciz  "test.c"                        # string offset=30
.Linfo_string2:
    .asciz  "/home/cloudcome/ebpf/trace/btf" # string offset=37
.Linfo_string3:
    .asciz  "test"                          # string offset=68
.Linfo_string4:
    .asciz  "int"                           # string offset=73
.Linfo_string5:
    .asciz  "t"                             # string offset=77
.Linfo_string6:
    .asciz  "a"                             # string offset=79
.Linfo_string7:
    .asciz  "b"                             # string offset=81
.Linfo_string8:
    .asciz  "char"                          # string offset=83
.Linfo_string9:
    .asciz  "A"                             # string offset=88
    .section    .BTF,"",@progbits
    .short  60319                           # 0xeb9f
    .byte   1
    .byte   0
    .long   24
    .long   0
    .long   112
    .long   112
    .long   106
    .long   0                               # BTF_KIND_FUNC_PROTO(id = 1)
    .long   218103809                       # 0xd000001
    .long   2
    .long   0
    .long   3
    .long   1                               # BTF_KIND_INT(id = 2)
    .long   16777216                        # 0x1000000
    .long   4
    .long   16777248                        # 0x1000020
    .long   0                               # BTF_KIND_PTR(id = 3)
    .long   33554432                        # 0x2000000
    .long   4
    .long   5                               # BTF_KIND_STRUCT(id = 4)
    .long   67108866                        # 0x4000002
    .long   8
    .long   7
    .long   2
    .long   0                               # 0x0
    .long   9
    .long   5
    .long   32                              # 0x20
    .long   11                              # BTF_KIND_INT(id = 5)
    .long   16777216                        # 0x1000000
    .long   1
    .long   16777224                        # 0x1000008
    .long   16                              # BTF_KIND_FUNC(id = 6)
    .long   201326593                       # 0xc000001
    .long   1
    .byte   0                               # string offset=0
    .ascii  "int"                           # string offset=1
    .byte   0
    .byte   65                              # string offset=5
    .byte   0
    .byte   97                              # string offset=7
    .byte   0
    .byte   98                              # string offset=9
    .byte   0
    .ascii  "char"                          # string offset=11
    .byte   0
    .ascii  "test"                          # string offset=16
    .byte   0
    .ascii  ".text"                         # string offset=21
    .byte   0
    .ascii  "/home/cloudcome/ebpf/trace/btf/test.c" # string offset=27
    .byte   0
    .ascii  "int test(struct A *t) {"       # string offset=65
    .byte   0
    .ascii  "    return t->a;"              # string offset=89
    .byte   0
    .section    .BTF.ext,"",@progbits
    .short  60319                           # 0xeb9f
    .byte   1
    .byte   0
    .long   32
    .long   0
    .long   20
    .long   20
    .long   60
    .long   80
    .long   0
    .long   8                               # FuncInfo
    .long   21                              # FuncInfo section string offset=21
    .long   1
    .long   .Lfunc_begin0
    .long   6
    .long   16                              # LineInfo
    .long   21                              # LineInfo section string offset=21
    .long   3
    .long   .Lfunc_begin0
    .long   27
    .long   65
    .long   6144                            # Line 6 Col 0
    .long   .Ltmp2
    .long   27
    .long   89
    .long   7180                            # Line 7 Col 12
    .long   .Ltmp3
    .long   27
    .long   89
    .long   7173                            # Line 7 Col 5
    .addrsig
    .section    .debug_line,"",@progbits
.Lline_table_start0:
anakryiko commented 2 years ago

@cloudcomes can you share .o file itself? Upload somewhere? E.g., https://gist.github.com/ or something like that?