Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当pthread和虚拟函数爆炸时,如何跟踪riscv指令上的跳转?_C_Multithreading_Binary_Pthreads_Riscv - Fatal编程技术网

当pthread和虚拟函数爆炸时,如何跟踪riscv指令上的跳转?

当pthread和虚拟函数爆炸时,如何跟踪riscv指令上的跳转?,c,multithreading,binary,pthreads,riscv,C,Multithreading,Binary,Pthreads,Riscv,我正在编写一个工具,用于跟踪riscv指令上的跳转(JAL/JALR)指令。我正在使用https://github.com/illumine/disk-benchmark/blob/master/src/disk-benchmark.c测试我的工具的磁盘基准测试。当不使用虚拟函数和pthread时,该工具跟踪二进制文件上的跳转,但在使用pthread时难以跟踪跳转。以下是riscv上二进制文件的objdump: 0000000000011d8e <main>:    11d8e:

我正在编写一个工具,用于跟踪riscv指令上的跳转(
JAL/JALR
)指令。我正在使用
https://github.com/illumine/disk-benchmark/blob/master/src/disk-benchmark.c
测试我的工具的磁盘基准测试。当不使用虚拟函数和pthread时,该工具跟踪二进制文件上的跳转,但在使用pthread时难以跟踪跳转。以下是riscv上二进制文件的objdump:

0000000000011d8e <main>:
   11d8e:   de010113            addi    sp,sp,-544
   11d92:   20113c23            sd  ra,536(sp)
   11d96:   20813823            sd  s0,528(sp)
   11d9a:   1400                    addi    s0,sp,544
   11d9c:   87aa                    mv  a5,a0
   11d9e:   ecb43023            sd  a1,-320(s0)
   11da2:   ecf42623            sw  a5,-308(s0)
   11da6:   fe043023            sd  zero,-32(s0)
   11daa:   fc043c23            sd  zero,-40(s0)
   11dae:   ed040793            addi    a5,s0,-304
   11db2:   853e                    mv  a0,a5
   11db4:   8aeff0ef            jal ra,10e62 <init_thread_work>
   11db8:   ecc42703            lw  a4,-308(s0)
   11dbc:   ed040793            addi    a5,s0,-304
   11dc0:   ec043603            ld  a2,-320(s0)
   11dc4:   85ba                    mv  a1,a4
   11dc6:   853e                    mv  a0,a5
   11dc8:   e60ff0ef            jal ra,11428 <parse_cli_arguments>
   11dcc:   87aa                    mv  a5,a0
   11dce:   c385                    beqz    a5,11dee <main+0x60>
   11dd0:   67d5                    lui a5,0x15
   11dd2:   1287b783            ld  a5,296(a5) # 15128 <stderr@@GLIBC_2.26>
   11dd6:   86be                    mv  a3,a5
   11dd8:   02000613            li  a2,32
   11ddc:   4585                    li  a1,1
   11dde:   67d1                    lui a5,0x14
   11de0:   b7078513            addi    a0,a5,-1168 # 13b70 <__stat+0x4c0>
   11de4:   f0dfe0ef            jal ra,10cf0 <fwrite@plt>
   11de8:   4505                    li  a0,1
   11dea:   e17fe0ef            jal ra,10c00 <exit@plt>
   11dee:   f4842783            lw  a5,-184(s0)
   11df2:   12078163            beqz    a5,11f14 <main+0x186>
   11df6:   ee042783            lw  a5,-288(s0)
   11dfa:   45a1                    li  a1,8
   11dfc:   853e                    mv  a0,a5
   11dfe:   e43fe0ef            jal ra,10c40 <calloc@plt>
   11e02:   87aa                    mv  a5,a0
   11e04:   fef43023            sd  a5,-32(s0)
   11e08:   ee042783            lw  a5,-288(s0)
   11e0c:   0e000593            li  a1,224
   11e10:   853e                    mv  a0,a5
   11e12:   e2ffe0ef            jal ra,10c40 <calloc@plt>
   11e16:   87aa                    mv  a5,a0
   11e18:   fcf43c23            sd  a5,-40(s0)
   11e1c:   fe042623            sw  zero,-20(s0)
   11e20:   a841                    j   11eb0 <main+0x122>
   11e22:   fec42703            lw  a4,-20(s0)
   11e26:   87ba                    mv  a5,a4
   11e28:   078e                    slli    a5,a5,0x3
   11e2a:   8f99                    sub a5,a5,a4
   11e2c:   0796                    slli    a5,a5,0x5
   11e2e:   873e                    mv  a4,a5
   11e30:   fd843783            ld  a5,-40(s0)
   11e34:   973e                    add a4,a4,a5
   11e36:   fec42683            lw  a3,-20(s0)
   11e3a:   ed040793            addi    a5,s0,-304
   11e3e:   8636                    mv  a2,a3
   11e40:   85ba                    mv  a1,a4
   11e42:   853e                    mv  a0,a5
   11e44:   92eff0ef            jal ra,10f72 <copy_thread_work>
   11e48:   fec42783            lw  a5,-20(s0)
   11e4c:   078e                    slli    a5,a5,0x3
   11e4e:   fe043703            ld  a4,-32(s0)
   11e52:   00f70533            add a0,a4,a5
   11e56:   fec42703            lw  a4,-20(s0)
   11e5a:   87ba                    mv  a5,a4
   11e5c:   078e                    slli    a5,a5,0x3
   11e5e:   8f99                    sub a5,a5,a4
   11e60:   0796                    slli    a5,a5,0x5
   11e62:   873e                    mv  a4,a5
   11e64:   fd843783            ld  a5,-40(s0)
   11e68:   97ba                    add a5,a5,a4
   11e6a:   86be                    mv  a3,a5
   11e6c:   000117b7            lui a5,0x11
   11e70:   76078613            addi    a2,a5,1888 # 11760 <do_benchmark>
   11e74:   4581                    li  a1,0
   11e76:   e0bfe0ef            jal ra,10c80 <pthread_create@plt>
   11e7a:   87aa                    mv  a5,a0
   11e7c:   faf42a23            sw  a5,-76(s0)
   11e80:   fb442783            lw  a5,-76(s0)
   11e84:   2781                    sext.w  a5,a5
   11e86:   c385                    beqz    a5,11ea6 <main+0x118>
   11e88:   67d5                    lui a5,0x15
   11e8a:   1287b703            ld  a4,296(a5) # 15128 <stderr@@GLIBC_2.26>
   11e8e:   fb442783            lw  a5,-76(s0)
   11e92:   863e                    mv  a2,a5
   11e94:   67d1                    lui a5,0x14
   11e96:   b9878593            addi    a1,a5,-1128 # 13b98 <__stat+0x4e8>
   11e9a:   853a                    mv  a0,a4
   11e9c:   e35fe0ef            jal ra,10cd0 <fprintf@plt>
   11ea0:   4505                    li  a0,1
   11ea2:   d5ffe0ef            jal ra,10c00 <exit@plt>
   11ea6:   fec42783            lw  a5,-20(s0)
   11eaa:   2785                    addiw   a5,a5,1
   11eac:   fef42623            sw  a5,-20(s0)
   11eb0:   ee042703            lw  a4,-288(s0)
   11eb4:   fec42783            lw  a5,-20(s0)
   11eb8:   2781                    sext.w  a5,a5
   11eba:   f6e7c4e3            blt a5,a4,11e22 <main+0x94>
   11ebe:   fe042623            sw  zero,-20(s0)
   11ec2:   a00d                    j   11ee4 <main+0x156>
   11ec4:   fec42783            lw  a5,-20(s0)
   11ec8:   078e                    slli    a5,a5,0x3
   11eca:   fe043703            ld  a4,-32(s0)
   11ece:   97ba                    add a5,a5,a4
   11ed0:   639c                    ld  a5,0(a5)
   11ed2:   4581                    li  a1,0
   11ed4:   853e                    mv  a0,a5
   11ed6:   e0bfe0ef            jal ra,10ce0 <pthread_join@plt>
   11eda:   fec42783            lw  a5,-20(s0)
   11ede:   2785                    addiw   a5,a5,1
   11ee0:   fef42623            sw  a5,-20(s0)
   11ee4:   ee042703            lw  a4,-288(s0)
   11ee8:   fec42783            lw  a5,-20(s0)
   11eec:   2781                    sext.w  a5,a5
   11eee:   fce7cbe3            blt a5,a4,11ec4 <main+0x136>
   11ef2:   fd843503            ld  a0,-40(s0)
   11ef6:   dbbfe0ef            jal ra,10cb0 <free@plt>
   11efa:   fe043503            ld  a0,-32(s0)
   11efe:   db3fe0ef            jal ra,10cb0 <free@plt>
   11f02:   4529                    li  a0,10
   11f04:   e3dfe0ef            jal ra,10d40 <putchar@plt>
   11f08:   f4c42783            lw  a5,-180(s0)
   11f0c:   853e                    mv  a0,a5
   11f0e:   d13fe0ef            jal ra,10c20 <sleep@plt>
   11f12:   b5d5                    j   11df6 <main+0x68>
   11f14:   4501                    li  a0,0
   11f16:   d7bfe0ef            jal ra,10c90 <time@plt>
   11f1a:   fca43823            sd  a0,-48(s0)
   11f1e:   df3fe0ef            jal ra,10d10 <clock@plt>
   11f22:   fca43423            sd  a0,-56(s0)
   11f26:   ee042783            lw  a5,-288(s0)
   11f2a:   45a1                    li  a1,8
   11f2c:   853e                    mv  a0,a5
   11f2e:   d13fe0ef            jal ra,10c40 <calloc@plt>
   11f32:   87aa                    mv  a5,a0
   11f34:   fef43023            sd  a5,-32(s0)
   11f38:   ee042783            lw  a5,-288(s0)
   11f3c:   0e000593            li  a1,224
   11f40:   853e                    mv  a0,a5
   11f42:   cfffe0ef            jal ra,10c40 <calloc@plt>
   11f46:   87aa                    mv  a5,a0
   11f48:   fcf43c23            sd  a5,-40(s0)
   11f4c:   fe042623            sw  zero,-20(s0)
   11f50:   a841                    j   11fe0 <main+0x252>
   11f52:   fec42703            lw  a4,-20(s0)
   11f56:   87ba                    mv  a5,a4
   11f58:   078e                    slli    a5,a5,0x3
   11f5a:   8f99                    sub a5,a5,a4
   11f5c:   0796                    slli    a5,a5,0x5
   11f5e:   873e                    mv  a4,a5
   11f60:   fd843783            ld  a5,-40(s0)
   11f64:   973e                    add a4,a4,a5
   11f66:   fec42683            lw  a3,-20(s0)
   11f6a:   ed040793            addi    a5,s0,-304
   11f6e:   8636                    mv  a2,a3
   11f70:   85ba                    mv  a1,a4
   11f72:   853e                    mv  a0,a5
   11f74:   ffffe0ef            jal ra,10f72 <copy_thread_work>
   11f78:   fec42783            lw  a5,-20(s0)
   11f7c:   078e                    slli    a5,a5,0x3
   11f7e:   fe043703            ld  a4,-32(s0)
   11f82:   00f70533            add a0,a4,a5
   11f86:   fec42703            lw  a4,-20(s0)
   11f8a:   87ba                    mv  a5,a4
   11f8c:   078e                    slli    a5,a5,0x3
   11f8e:   8f99                    sub a5,a5,a4
   11f90:   0796                    slli    a5,a5,0x5
   11f92:   873e                    mv  a4,a5
   11f94:   fd843783            ld  a5,-40(s0)
   11f98:   97ba                    add a5,a5,a4
   11f9a:   86be                    mv  a3,a5
   11f9c:   000117b7            lui a5,0x11
   11fa0:   76078613            addi    a2,a5,1888 # 11760 <do_benchmark>
   11fa4:   4581                    li  a1,0
   11fa6:   cdbfe0ef            jal ra,10c80 <pthread_create@plt>
   11faa:   87aa                    mv  a5,a0
   11fac:   faf42a23            sw  a5,-76(s0)
   11fb0:   fb442783            lw  a5,-76(s0)
   11fb4:   2781                    sext.w  a5,a5
   11fb6:   c385                    beqz    a5,11fd6 <main+0x248>
   11fb8:   67d5                    lui a5,0x15
   11fba:   1287b703            ld  a4,296(a5) # 15128 <stderr@@GLIBC_2.26>
   11fbe:   fb442783            lw  a5,-76(s0)
   11fc2:   863e                    mv  a2,a5
   11fc4:   67d1                    lui a5,0x14
   11fc6:   bc878593            addi    a1,a5,-1080 # 13bc8 <__stat+0x518>
   11fca:   853a                    mv  a0,a4
   11fcc:   d05fe0ef            jal ra,10cd0 <fprintf@plt>
   11fd0:   4505                    li  a0,1
   11fd2:   c2ffe0ef            jal ra,10c00 <exit@plt>
   11fd6:   fec42783            lw  a5,-20(s0)
   11fda:   2785                    addiw   a5,a5,1
   11fdc:   fef42623            sw  a5,-20(s0)
   11fe0:   ee042703            lw  a4,-288(s0)
   11fe4:   fec42783            lw  a5,-20(s0)
   11fe8:   2781                    sext.w  a5,a5
   11fea:   f6e7c4e3            blt a5,a4,11f52 <main+0x1c4>
   11fee:   4581                    li  a1,0
   11ff0:   fd843503            ld  a0,-40(s0)
   11ff4:   a38ff0ef            jal ra,1122c <debug_thread_results_header>
   11ff8:   fe042623            sw  zero,-20(s0)
   11ffc:   a00d                    j   1201e <main+0x290>
   11ffe:   fec42783            lw  a5,-20(s0)
   12002:   078e                    slli    a5,a5,0x3
   12004:   fe043703            ld  a4,-32(s0)
   12008:   97ba                    add a5,a5,a4
   1200a:   639c                    ld  a5,0(a5)
   1200c:   4581                    li  a1,0
   1200e:   853e                    mv  a0,a5
   12010:   cd1fe0ef            jal ra,10ce0 <pthread_join@plt>
   12014:   fec42783            lw  a5,-20(s0)
   12018:   2785                    addiw   a5,a5,1
   1201a:   fef42623            sw  a5,-20(s0)
   1201e:   ee042703            lw  a4,-288(s0)
   12022:   fec42783            lw  a5,-20(s0)
   12026:   2781                    sext.w  a5,a5
   12028:   fce7cbe3            blt a5,a4,11ffe <main+0x270>
   1202c:   ee042683            lw  a3,-288(s0)
   12030:   de040793            addi    a5,s0,-544
   12034:   ed040713            addi    a4,s0,-304
   12038:   fd843603            ld  a2,-40(s0)
   1203c:   85ba                    mv  a1,a4
   1203e:   853e                    mv  a0,a5
   12040:   a0dff0ef            jal ra,11a4c <calculate_summaries>
   12044:   ed040793            addi    a5,s0,-304
   12048:   de040713            addi    a4,s0,-544
   1204c:   0e000693            li  a3,224
   12050:   8636                    mv  a2,a3
   12052:   85ba                    mv  a1,a4
   12054:   853e                    mv  a0,a5
   12056:   cfbfe0ef            jal ra,10d50 <memcpy@plt>
   1205a:   4585                    li  a1,1
   1205c:   fd843503            ld  a0,-40(s0)
   12060:   9ccff0ef            jal ra,1122c <debug_thread_results_header>
   12064:   ed040793            addi    a5,s0,-304
   12068:   853e                    mv  a0,a5
   1206a:   852ff0ef            jal ra,110bc <debug_thread_results>
   1206e:   4501                    li  a0,0
   12070:   c21fe0ef            jal ra,10c90 <time@plt>
   12074:   fca43023            sd  a0,-64(s0)
   12078:   c99fe0ef            jal ra,10d10 <clock@plt>
   1207c:   faa43c23            sd  a0,-72(s0)
   12080:   f3c42783            lw  a5,-196(s0)
   12084:   ef9d                    bnez    a5,120c2 <main+0x334>
   12086:   fd043583            ld  a1,-48(s0)
   1208a:   fc043503            ld  a0,-64(s0)
   1208e:   ce3fe0ef            jal ra,10d70 <difftime@plt>
   12092:   22a506d3            fmv.d   fa3,fa0
   12096:   fb843703            ld  a4,-72(s0)
   1209a:   fc843783            ld  a5,-56(s0)
   1209e:   40f707b3            sub a5,a4,a5
   120a2:   d227f753            fcvt.d.l    fa4,a5
   120a6:   67d1                    lui a5,0x14
   120a8:   c487b787            fld fa5,-952(a5) # 13c48 <__stat+0x598>
   120ac:   1af777d3            fdiv.d  fa5,fa4,fa5
   120b0:   e2078653            fmv.x.d a2,fa5
   120b4:   e20685d3            fmv.x.d a1,fa3
   120b8:   67d1                    lui a5,0x14
   120ba:   bf878513            addi    a0,a5,-1032 # 13bf8 <__stat+0x548>
   120be:   b73fe0ef            jal ra,10c30 <printf@plt>
   120c2:   f4442783            lw  a5,-188(s0)
   120c6:   c399                    beqz    a5,120cc <main+0x33e>
   120c8:   ac4ff0ef            jal ra,1138c <print_system_datetime>
   120cc:   fd843503            ld  a0,-40(s0)
   120d0:   be1fe0ef            jal ra,10cb0 <free@plt>
   120d4:   fe043503            ld  a0,-32(s0)
   120d8:   bd9fe0ef            jal ra,10cb0 <free@plt>
   120dc:   4501                    li  a0,0
   120de:   c43fe0ef            jal ra,10d20 <pthread_exit@plt>
0000000000011d8e:
11d8e:de010113附加sp,sp,-544
11d92:20113c23 sd ra,536(sp)
11d96:20813823 sd S0528(sp)
11d9a:1400 addi s0,sp,544
11d9c:87aa中压a5,a0
11d9e:ecb43023 sd a1,-320(s0)
11da2:ecf42623 sw a5,-308(s0)
11da6:fe043023标准差零点-32(s0)
11daa:fc043c23 sd零-40(s0)
11dae:ed040793 addi a5,s0,-304
11db2:853e mv a0,a5
11db4:8aeff0ef日航,10e62
11db8:ecc42703 lw a4,-308(s0)
11dbc:ed040793 addi a5,s0,-304
11dc0:ec043603 ld a2,-320(s0)
11dc4:85ba中压a1、a4
11dc6:853e mv a0,a5
11dc8:e60ff0ef日本航空公司,邮编11428
11dcc:87aa中压a5,a0
11dce:c385 beqz a5,11dee
11dd0:67d5 lui a5,0x15
11dd2:1287b783 ld A5296(a5)#15128
11dd6:86be mv a3,a5
11dd8:02000613 li a2,32
11ddc:4585 li a1,1
11dde:67d1 lui a5,0x14
11de0:b7078513 addi a0,a5,-1168#13b70
11de4:f0dfe0ef日航ra,10cf0
11de8:4505 li a0,1
11dea:e17fe0ef日本ra,10c00
11dee:f4842783 lw a5,-184(s0)
11df2:12078163 beqz a5,11f14
11df6:ee042783 lw a5,-288(s0)
11dfa:45a1 li a1,8
11dfc:853e mv a0,a5
11dfe:e43fe0ef日本航空公司,10c40
11e02:87aa中压a5,a0
11e04:fef43023 sd a5,-32(s0)
11e08:ee042783 lw a5,-288(s0)
11e0c:0e000593 li A1224
11e10:853e mv a0,a5
11e12:e2ffe0ef jal ra,10c40
11e16:87aa中压a5,a0
11e18:fcf43c23 sd a5,-40(s0)
11e1c:fe042623 sw零点-20(s0)
11e20:a841 j 11eb0
11e22:fec42703 lw a4,-20(s0)
11e26:87ba中压a5,a4
11e28:078e slli a5,a5,0x3
11e2a:8f99子a5、a5、a4
11e2c:0796 slli a5,a5,0x5
11e2e:873e mv a4,a5
11e30:fd843783 ld a5,-40(s0)
11e34:973e添加a4、a4、a5
11e36:fec42683 lw a3,-20(s0)
11e3a:ed040793增补a5,s0,-304
11e3e:8636 mv a2,a3
11e40:85ba中压a1、a4
11e42:853e mv a0,a5
11e44:92eff0ef日航,10f72
11e48:fec42783 lw a5,-20(s0)
11e4c:078e slli a5,a5,0x3
11e4e:fe043703 ld a4,-32(s0)
11e52:00f70533添加a0、a4、a5
11e56:fec42703 lw a4,-20(s0)
11e5a:87ba中压a5,a4
11e5c:078e slli a5,a5,0x3
11e5e:8f99子a5、a5、a4
11e60:0796 slli a5,a5,0x5
11e62:873e mv a4,a5
11e64:fd843783 ld a5,-40(s0)
11e68:97ba添加a5、a5、a4
11e6a:86be mv a3,a5
11e6c:000117b7 lui a5,0x11
11e70:76078613 addi a2,A51888#11760
11e74:4581 li a1,0
11e76:e0bfe0ef日航,10c80
11e7a:87aa mv a5,a0
11e7c:faf42a23 sw a5,-76(s0)
11e80:fb442783 lw a5,-76(s0)
11e84:2781西经a5,a5
11e86:c385 beqz a5,11ea6
11e88:67d5 lui a5,0x15
11e8a:1287b703 ld A4296(a5)#15128
11e8e:fb442783 lw a5,-76(s0)
11e92:863e mv a2,a5
11e94:67d1 lui a5,0x14
11e96:b9878593增补a1,a5,-1128#13b98
11e9a:853a mv a0,a4
11e9c:e35fe0ef日本航空公司,10cd0
11ea0:4505 li a0,1
11ea2:d5ffe0ef jal ra,10c00
11ea6:fec42783 lw a5,-20(s0)
11eaa:2785增补a5,a5,1
11eac:fef42623西南a5,-20(s0)
11eb0:ee042703 lw a4,-288(s0)
11eb4:fec42783
int main(int argc, char *argv[]){
  pthread_t *threads = NULL;
  ThreadWork_t thread_work, *threads_work = NULL;
  int rc, t;
  time_t start_time, stop_time;
  clock_t start_clock, stop_clock;

    /* Initialize the work and parse user options */
    init_thread_work(&thread_work);
    if( parse_cli_arguments( &thread_work, argc, argv) ){
        fprintf(stderr,"\nError while parsing arguments!\n");
        exit(ER_EXIT);
    }

    //if work continously, just block in the loop waiting for user to interrupt with Cntr-C
    if( thread_work.work_continously){
        while(1){
            threads = calloc( thread_work.threads, sizeof(pthread_t) );
            threads_work = calloc( thread_work.threads, sizeof(ThreadWork_t) );
            for(t=0; t<thread_work.threads; t++) {
                copy_thread_work(&thread_work, &threads_work[t], t );
                rc = pthread_create( &threads[t], NULL, do_benchmark, (void *) &threads_work[t] );
                if (rc){
                    fprintf(stderr,"\nError return code %d from pthread_create()",rc);
                    exit(ER_EXIT);
                }
            }
            for(t=0; t<thread_work.threads; t++)
                pthread_join( threads[t], NULL);
            free(threads_work);
            free(threads);
            printf("\n");
            sleep(thread_work.work_continously_sleep_brake);
        }
    }

    /* Start Wall and CPU clocks and fire threads */
    start_time = time(NULL);
    start_clock = clock();
    threads = calloc( thread_work.threads, sizeof(pthread_t) );
    threads_work = calloc( thread_work.threads, sizeof(ThreadWork_t) );
    for(t=0; t<thread_work.threads; t++) {
        copy_thread_work(&thread_work, &threads_work[t], t );
        rc = pthread_create( &threads[t], NULL, do_benchmark, (void *) &threads_work[t] );
        if (rc){
            fprintf(stderr,"\nERROR return code %d from pthread_create()",rc);
            exit(ER_EXIT);
        }
    }