gdb脚本 显示所有线程的stack大小

import os
import re

def get_map_range(map_range):
    map_ranges = map_range.split("-")
    range_from = int(map_ranges[0], 16)
    range_to = int(map_ranges[1], 16)
    return (range_from, range_to)
    
def show_threads_stack_info(verbose):
    (inferior,) = gdb.inferiors()
    proc_map_file_name = "/proc/{}/maps".format(inferior.pid) 
    proc_map_file = open(proc_map_file_name, 'r')
    map_ranges = []
    while True:
        line = proc_map_file.readline()
        if not line:
            break
        map_range = line.split()[0]
        (range_from, range_to) = get_map_range(map_range)
        map_ranges.append((map_range, range_from, range_to))

    totalSizeKB = 0
    totalPssKB = 0

    for thread in inferior.threads():
        thread.switch()
        frame = gdb.selected_frame()
        rsp_val = int(frame.read_register("rsp"))
        if verbose:
            print("------------------")
            gdb.execute("bt")
        for r in map_ranges:
            (map_range, range_from, range_to) = r
            if rsp_val>=range_from and rsp_val

在gdb里执行

show-threads-stack-info 1

你可能感兴趣的:(gdb脚本 显示所有线程的stack大小)