summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorzy <[email protected]>2023-11-21 04:43:15 -0500
committerzy <[email protected]>2023-11-21 04:43:15 -0500
commit6c105992fd9a97da2c059e67ff24476fd6dacb67 (patch)
tree487ef499e71950c620def5be4c10fd23d0305455 /source
parent6921e2bf2fc58ebf14123553e4c24c0fe3c47fdd (diff)
a lot of print
Diffstat (limited to 'source')
-rw-r--r--source/module/monitor_kernel_lib.c2
-rw-r--r--source/module/monitor_trace.c58
-rw-r--r--source/ucli_py/ucli.py19
3 files changed, 59 insertions, 20 deletions
diff --git a/source/module/monitor_kernel_lib.c b/source/module/monitor_kernel_lib.c
index 80708ab..e15e1e9 100644
--- a/source/module/monitor_kernel_lib.c
+++ b/source/module/monitor_kernel_lib.c
@@ -237,7 +237,7 @@ enum hrtimer_restart check_variable_cb(struct hrtimer *timer) {
do_each_thread(g, p) {
if (p->__state == TASK_RUNNING || __task_contributes_to_load(p) ||
- p->__state == TASK_IDLE) {
+ p->__state == TASK_IDLE || 1) {
tsk_info.et_type = 1; //! todo event type
tsk_info.id = event_id;
tsk_info.tv = vm_record.tv;
diff --git a/source/module/monitor_trace.c b/source/module/monitor_trace.c
index a07545b..0fe7905 100644
--- a/source/module/monitor_trace.c
+++ b/source/module/monitor_trace.c
@@ -93,9 +93,13 @@ static int copy_stack_frame_remote(struct task_struct *tsk,
struct mm_struct *mm;
mm = get_task_mm(tsk);
- if (!mm) return 0;
+ if (!mm) {
+ printk("copy_stack_frame_remote %d get_task_mm fail\n", tsk->pid);
+ return 0;
+ }
ret = orig_access_remote_vm(mm, (unsigned long)fp, frame, sizeof(*frame), 0);
+ printk("copy_stack_frame_remote %d ret:%d\n", tsk->pid, ret);
mmput(mm);
return ret;
@@ -107,8 +111,16 @@ static inline void save_stack_trace_user_remote(struct task_struct *tsk,
const void __user *fp = (const void __user *)regs->bp;
int count = 0;
- if (in_atomic() || irqs_disabled()) {
- return;
+ if (in_atomic() ) {
+ printk("save_stack_trace_user_remote %d in_atomic\n",
+ tsk->pid);
+ // return;
+ }
+
+ if (irqs_disabled()) {
+ printk("save_stack_trace_user_remote %d irqs_disabled\n",
+ tsk->pid);
+ // return;
}
if (trace->nr_entries < trace->max_entries)
@@ -121,18 +133,33 @@ static inline void save_stack_trace_user_remote(struct task_struct *tsk,
frame.ret_addr = 0;
if (!copy_stack_frame_remote(tsk, fp, &frame)) {
+ printk("save_stack_trace_user_remote %d copy_stack_frame_remote fail\n",
+ tsk->pid);
break;
}
- if ((unsigned long)fp < regs->sp) break;
-
+ if ((unsigned long)fp < regs->sp) {
+ printk("save_stack_trace_user_remote %d fp < sp count:%d\n", tsk->pid,
+ count);
+ break; // 如果fp小于sp,说明已经到了栈底,退出
+ }
+ // 如果返回地址不为0,说明是一个有效的栈帧,保存返回地址
if (frame.ret_addr) {
trace->entries[trace->nr_entries++] = frame.ret_addr;
- } else
- break;
+ printk("save_stack_trace_user_remote %d ret_addr:%lx\n", tsk->pid,
+ frame.ret_addr);
+ } else{
+ printk("save_stack_trace_user_remote %d no ret_addr", tsk->pid);
+ // break;
+ continue;
+ }
- if (fp == frame.next_fp) break;
- fp = frame.next_fp;
+ // 如果fp指向自己,说明已经到了栈底,退出
+ if (fp == frame.next_fp) {
+ printk("save_stack_trace_user_remote %d fp == next_fp", tsk->pid);
+ break;
+ }
+ fp = frame.next_fp; // 否则,继续向下遍历
count++;
/**
@@ -204,10 +231,19 @@ static void diagnose_save_stack_trace_user_remote(struct task_struct *tsk,
* Trace user stack if we are not a kernel thread
*/
if (tsk->mm) {
+ printk("save_stack_trace_user_remote %d mm\n", tsk->pid);
save_stack_trace_user_remote(tsk, &trace);
}
if (trace.nr_entries < trace.max_entries)
trace.entries[trace.nr_entries++] = ULONG_MAX;
+
+ printk("save_stack_trace_user_remote %d, stack: [", tsk->pid);
+ int i = 0;
+ for (i = 0; i < BACKTRACE_DEPTH; i++)
+ {
+ printk("%lx, ", backtrace[i]);
+ }
+ printk("]\n");
}
void diag_task_brief(struct task_struct *tsk, task_detail *detail) {
@@ -311,10 +347,10 @@ void diag_task_user_stack(struct task_struct *tsk, user_stack_detail *detail) {
detail->bp = bp;
if (tsk == current) {
- // printk("diag_task_user_stack current\n");
+ printk("diag_task_user_stack %d current\n", tsk->pid);
diagnose_save_stack_trace_user(detail->stack);
} else {
- // printk("diag_task_user_stack no current\n");
+ printk("diag_task_user_stack %d no current\n", tsk->pid);
diagnose_save_stack_trace_user_remote(tsk, detail->stack);
}
}
diff --git a/source/ucli_py/ucli.py b/source/ucli_py/ucli.py
index bd88f61..55c2f33 100644
--- a/source/ucli_py/ucli.py
+++ b/source/ucli_py/ucli.py
@@ -148,7 +148,7 @@ symbols = parse_kallsyms("/proc/kallsyms")
def diag_printf_kern_stack(kern_stack: kern_stack_detail):
print(" 内核态堆栈:")
for i in range(BACKTRACE_DEPTH - 1, -1, -1):
- if kern_stack.stack[i] == ctypes.c_ulong(-1).value or kern_stack.stack[i] == 0:
+ if (kern_stack.stack[i] == ctypes.c_ulong(-1)) or (kern_stack.stack[i] == 0):
continue
# temp = kern_stack.stack[i]
nearest_symbol, offset = print_stack_trace(symbols, kern_stack.stack[i])
@@ -187,7 +187,9 @@ def diag_printf_user_stack(pid: int, user_stack: user_stack_detail):
p = None
print(" 用户态堆栈:")
for i in range(BACKTRACE_DEPTH - 1, -1, -1):
- if user_stack.stack[i] == ctypes.c_ulong(-1).value or user_stack.stack[i] == 0:
+ a = user_stack.stack[i]
+
+ if (user_stack.stack[i] == 18446744073709551615) or (user_stack.stack[i] == 0):
continue
if not p:
p = ProcMapsParser(pid)
@@ -239,12 +241,13 @@ def load_monitor_extract(buf, len, _):
f"##CGROUP:[{tsk_info.task.cgroup_buf.decode()}] {tsk_info.task.pid} [{seq:03d}] 采样命中[{'R' if tsk_info.task.state == 0 else 'D'}]"
)
# 打印 tsk_info
- # print_structure(tsk_info, struct_name="variable_monitor_task")
- printk_task_brief(tsk_info.task)
- diag_printf_user_stack(tsk_info.task.pid, tsk_info.user_stack)
- diag_printf_kern_stack(tsk_info.kern_stack)
- print(f"#* 0xffffffffffffff {tsk_info.task.comm.decode()} (UNKNOWN)")
- diag_printf_proc_chains(tsk_info.proc_chains)
+ print_structure(tsk_info, struct_name="variable_monitor_task")
+ # printk_task_brief(tsk_info.task)
+ # diag_printf_user_stack(tsk_info.task.pid, tsk_info.user_stack)
+ # # for user_stack :18446744073709551615
+ # print(f"#* 0xffffffffffffff {tsk_info.task.comm.decode()} (UNKNOWN)")
+ # diag_printf_kern_stack(tsk_info.kern_stack)
+ # diag_printf_proc_chains(tsk_info.proc_chains)
print("##")