mirror of
https://github.com/sstefani/mtrace.git
synced 2026-04-30 19:09:15 +08:00
better kill behaviour
This commit is contained in:
parent
4fe84ebf6c
commit
95b0d7b7b8
10
breakpoint.c
10
breakpoint.c
@ -302,9 +302,8 @@ void enable_scratch_hw_bp(struct task *task, struct breakpoint *bp)
|
||||
if (unlikely(bp->deleted))
|
||||
return;
|
||||
|
||||
if (unlikely(bp->type != BP_HW_SCRATCH))
|
||||
return;
|
||||
|
||||
assert(bp->type == BP_HW_SCRATCH);
|
||||
assert(bp->hw);
|
||||
assert(bp->hw_bp_slot == HW_BP_SCRATCH_SLOT);
|
||||
|
||||
if (task->hw_bp[bp->hw_bp_slot] != bp)
|
||||
@ -316,9 +315,8 @@ void disable_scratch_hw_bp(struct task *task, struct breakpoint *bp)
|
||||
if (unlikely(bp->deleted))
|
||||
return;
|
||||
|
||||
if (unlikely(bp->type != BP_HW_SCRATCH))
|
||||
return;
|
||||
|
||||
assert(bp->type == BP_HW_SCRATCH);
|
||||
assert(bp->hw);
|
||||
assert(bp->hw_bp_slot == HW_BP_SCRATCH_SLOT);
|
||||
|
||||
disable_hw_bp(task, bp);
|
||||
|
||||
@ -676,13 +676,10 @@ static int process_rb_insert_block(struct process *process, unsigned long addr,
|
||||
parent = *new;
|
||||
|
||||
if (addr <= this->addr && addr + n > this->addr) {
|
||||
if (unlikely(options.kill || options.verbose > 2)) {
|
||||
process_dump_collision(process, this, addr, size, operation);
|
||||
process_dump_collision(process, this, addr, size, operation);
|
||||
|
||||
if (options.kill)
|
||||
abort();
|
||||
}
|
||||
return -1;
|
||||
if (options.kill)
|
||||
abort();
|
||||
}
|
||||
|
||||
if (addr < this->addr)
|
||||
@ -1258,12 +1255,11 @@ void process_munmap(struct process *process, struct mt_msg *mt_msg, void *payloa
|
||||
break;
|
||||
|
||||
if (!is_mmap(block->stack_node->stack->operation)) {
|
||||
if (unlikely(options.kill || options.verbose > 2)) {
|
||||
fprintf(stderr, ">>> block missmatch pid:%d MAP<>MALLOC %#lx\n", process->pid, ptr);
|
||||
fprintf(stderr, ">>> block missmatch pid:%d MAP<>MALLOC %#lx\n", process->pid, ptr);
|
||||
|
||||
if (options.kill)
|
||||
abort();
|
||||
|
||||
if (options.kill)
|
||||
abort();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1384,12 +1380,10 @@ void process_free(struct process *process, struct mt_msg *mt_msg, void *payload)
|
||||
block = process_rb_search(&process->block_table, ptr);
|
||||
if (block) {
|
||||
if (is_mmap(block->stack_node->stack->operation)) {
|
||||
if (unlikely(options.kill || options.verbose > 2)) {
|
||||
fprintf(stderr, ">>> block missmatch pid:%d MAP<>MALLOC %#lx\n", process->pid, ptr);
|
||||
fprintf(stderr, ">>> block missmatch pid:%d MAP<>MALLOC %#lx\n", process->pid, ptr);
|
||||
|
||||
if (options.kill)
|
||||
abort();
|
||||
}
|
||||
if (options.kill)
|
||||
abort();
|
||||
}
|
||||
|
||||
if (!is_sane(block, mt_msg->operation)) {
|
||||
@ -1418,11 +1412,9 @@ void process_free(struct process *process, struct mt_msg *mt_msg, void *payload)
|
||||
}
|
||||
else {
|
||||
if (!process->attached) {
|
||||
if (unlikely(options.kill || options.verbose > 2)) {
|
||||
if (unlikely(options.kill)) {
|
||||
fprintf(stderr, ">>> block %#lx not found pid:%d\n", ptr, process->pid);
|
||||
|
||||
if (options.kill)
|
||||
abort();
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1505,12 +1497,11 @@ void process_alloc(struct process *process, struct mt_msg *mt_msg, void *payload
|
||||
|
||||
block = process_rb_search_range(&process->block_table, ptr, size);
|
||||
if (block) {
|
||||
if (unlikely(options.kill || options.verbose > 2)) {
|
||||
process_dump_collision(process, block, ptr, size, mt_msg->operation);
|
||||
process_dump_collision(process, block, ptr, size, mt_msg->operation);
|
||||
|
||||
if (options.kill)
|
||||
abort();
|
||||
|
||||
if (options.kill)
|
||||
abort();
|
||||
}
|
||||
process_rb_delete_block(process, block);
|
||||
}
|
||||
|
||||
|
||||
11
event.c
11
event.c
@ -241,11 +241,11 @@ static int handle_call_after(struct task *task, struct breakpoint *bp)
|
||||
start_time(&start);
|
||||
|
||||
#if HW_BREAKPOINTS > 0
|
||||
if (bp->hw)
|
||||
disable_scratch_hw_bp(task, bp);
|
||||
disable_scratch_hw_bp(task, bp);
|
||||
#endif
|
||||
|
||||
task->libsym->func->report_out(task, task->libsym);
|
||||
if (task->libsym->func->report_out)
|
||||
task->libsym->func->report_out(task, task->libsym);
|
||||
|
||||
if (unlikely(options.verbose > 1))
|
||||
set_timer(&start, &report_out_time);
|
||||
@ -312,13 +312,14 @@ static void handle_breakpoint(struct task *task)
|
||||
|
||||
save_param_context(task);
|
||||
|
||||
if (libsym->func->report_out) {
|
||||
if (libsym->func->report_out || options.kill) {
|
||||
task->breakpoint = breakpoint_insert(task, get_return_addr(task), NULL, BP_HW_SCRATCH);
|
||||
if (likely(task->breakpoint)) {
|
||||
task->libsym = libsym;
|
||||
task->breakpoint->on_hit = handle_call_after;
|
||||
|
||||
#if HW_BREAKPOINTS > 0
|
||||
enable_scratch_hw_bp(task, task->breakpoint);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ static void usage(void)
|
||||
" -i, --interactive interactive client mode\n"
|
||||
#endif
|
||||
" -O, --omit=FILE do not place breakpoint in this file\n"
|
||||
" -k, --kill abort mtrace-ng due unexpected error conditon\n"
|
||||
" -k, --kill abort mtrace-ng due unexpected error condition\n"
|
||||
" -l, --logfile use log file instead of socket connection\n"
|
||||
" -L, --long long dump includes map filename\n"
|
||||
" -n, --nocpp disable trace of c++ allocation operators (faster for libstdc++)\n"
|
||||
|
||||
18
report.c
18
report.c
@ -52,15 +52,14 @@ static void report_alloc64(struct task *task, enum mt_operation op, unsigned lon
|
||||
alloc->size = (uint64_t)size;
|
||||
|
||||
if (depth) {
|
||||
if (libsym)
|
||||
alloc->data[i++] = libsym->addr;
|
||||
alloc->data[i++] = libsym->addr;
|
||||
|
||||
if (likely(backtrace_init_unwind(task) >= 0)) {
|
||||
while(i < depth) {
|
||||
if (likely(backtrace_location_type(task) != LIBTYPE_LOADER)) {
|
||||
alloc->data[i] = (uint64_t)backtrace_get_ip(task);
|
||||
|
||||
if (likely(!i || alloc->data[i - 1] != alloc->data[i])) {
|
||||
if (likely(alloc->data[i - 1] != alloc->data[i])) {
|
||||
if (unlikely(!alloc->data[i]))
|
||||
break;
|
||||
|
||||
@ -88,15 +87,14 @@ static void report_alloc32(struct task *task, enum mt_operation op, unsigned lon
|
||||
alloc->size = (uint32_t)size;
|
||||
|
||||
if (depth) {
|
||||
if (libsym)
|
||||
alloc->data[i++] = libsym->addr;
|
||||
alloc->data[i++] = libsym->addr;
|
||||
|
||||
if (likely(backtrace_init_unwind(task) >= 0)) {
|
||||
while(i < depth) {
|
||||
if (likely(backtrace_location_type(task) != LIBTYPE_LOADER)) {
|
||||
alloc->data[i] = (uint32_t)backtrace_get_ip(task);
|
||||
|
||||
if (likely(!i || alloc->data[i - 1] != alloc->data[i])) {
|
||||
if (likely(alloc->data[i - 1] != alloc->data[i])) {
|
||||
if (unlikely(!alloc->data[i]))
|
||||
break;
|
||||
|
||||
@ -128,10 +126,6 @@ static void report_alloc(struct task *task, enum mt_operation op, unsigned long
|
||||
report_alloc32(task, op, ptr, size, depth, libsym);
|
||||
}
|
||||
|
||||
static void _null(struct task *task, struct library_symbol *libsym)
|
||||
{
|
||||
}
|
||||
|
||||
static void _report_alloc_op(struct task *task, struct library_symbol *libsym, enum mt_operation op)
|
||||
{
|
||||
unsigned long size = fetch_param(task, 0);
|
||||
@ -159,7 +153,7 @@ static void _report_free_op(struct task *task, struct library_symbol *libsym, en
|
||||
{
|
||||
unsigned long addr = fetch_param(task, 0);
|
||||
|
||||
report_alloc(task, op, addr, 0, options.sanity ? options.bt_depth : 0, NULL);
|
||||
report_alloc(task, op, addr, 0, options.sanity ? options.bt_depth : 0, libsym);
|
||||
}
|
||||
|
||||
static void report_free(struct task *task, struct library_symbol *libsym)
|
||||
@ -347,7 +341,7 @@ static const struct function flist[] = {
|
||||
{ "posix_memalign", "posix_memalign", 0, NULL, _report_posix_memalign },
|
||||
{ "mmap", "mmap", 0, NULL, _report_mmap },
|
||||
{ "mmap64", "mmap64", 1, NULL, _report_mmap64 },
|
||||
{ "munmap", "munmap", 0, report_munmap, _null },
|
||||
{ "munmap", "munmap", 0, report_munmap, NULL },
|
||||
{ "memalign", "memalign", 0, NULL, _report_memalign },
|
||||
{ "aligned_alloc", "aligned_alloc", 1, NULL, _report_aligned_alloc },
|
||||
{ "valloc", "valloc", 1, NULL, _report_valloc },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user