#!/usr/bin/tclsh## Parse the output of## objdump -d sqlite3.o## for x64 and generate a report showing:## (1) Stack used by each function# (2) Recursion paths and their aggregate stack depth#set getStack 0while {![eof stdin]} {set line [gets stdin]if {[regexp {^[0-9a-f]+ <([^>]+)>:\s*$} $line all procname]} {set curfunc $procnameset root($curfunc) 1set calls($curfunc) {}set calledby($curfunc) {}set recursive($curfunc) {}set stkdepth($curfunc) 0set getStack 1continue}if {[regexp {callq? +[0-9a-z]+ <([^>]+)>} $line all other]} {set key [list $curfunc $other]set callpair($key) 1unset -nocomplain root($curfunc)continue}if {[regexp {sub +\$(0x[0-9a-z]+),%[er]sp} $line all xdepth]} {if {$getStack} {scan $xdepth %x depthset stkdepth($curfunc) $depthset getStack 0}continue}}puts "****************** Stack Usage By Function ********************"set sdlist {}foreach f [array names stkdepth] {lappend sdlist [list $stkdepth($f) $f]}foreach sd [lsort -integer -decr -index 0 $sdlist] {foreach {depth fname} $sd breakputs [format {%6d %s} $depth $fname]}puts "****************** Stack Usage By Recursion *******************"foreach key [array names callpair] {foreach {from to} $key breaklappend calls($from) $to# lappend calledby($to) $from}proc all_descendents {root} {global calls recursiveset todo($root) $rootset go 1while {$go} {set go 0foreach f [array names todo] {set path $todo($f)unset todo($f)if {![info exists calls($f)]} continueforeach x $calls($f) {if {$x==$root} {lappend recursive($root) [concat $path $root]} elseif {![info exists d($x)]} {set go 1set todo($x) [concat $path $x]set d($x) 1}}}}return [array names d]}set pathlist {}foreach f [array names recursive] {all_descendents $fforeach m $recursive($f) {set depth 0foreach b [lrange $m 0 end-1] {set depth [expr {$depth+$stkdepth($b)}]}lappend pathlist [list $depth $m]}}foreach path [lsort -integer -decr -index 0 $pathlist] {foreach {depth m} $path breakset first [lindex $m 0]puts [format {%6d %s %d} $depth $first $stkdepth($first)]foreach b [lrange $m 1 end] {puts " $b$stkdepth($b)"}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。