* Added arch_debug_contains_call() function that returns wether or not
a call chain contains a specific symbol (or address). * Added a new KDL command "calling" that you can use to get a list of threads that have a specific function in their call chain. * Removed extraneous white space. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24594 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005, Axel Dörfler, [email protected].
|
||||
* Copyright 2005-2008, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <SupportDefs.h>
|
||||
|
||||
struct kernel_args;
|
||||
struct thread;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -20,6 +21,8 @@ extern "C" {
|
||||
|
||||
status_t arch_debug_init(kernel_args *args);
|
||||
void *arch_debug_get_caller(void);
|
||||
bool arch_debug_contains_call(struct thread *thread, const char *symbol,
|
||||
addr_t start, addr_t end);
|
||||
void arch_debug_save_registers(int *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007, Haiku Inc. All rights reserved.
|
||||
* Copyright 2003-2008, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -264,6 +264,14 @@ arch_debug_save_registers(int *regs)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
arch_debug_contains_call(struct thread *thread, const char *symbol,
|
||||
addr_t start, addr_t end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
arch_debug_get_caller(void)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2006, Haiku Inc. All rights reserved.
|
||||
* Copyright 2003-2008, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -270,6 +270,14 @@ arch_debug_save_registers(int *regs)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
arch_debug_contains_call(struct thread *thread, const char *symbol,
|
||||
addr_t start, addr_t end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
arch_debug_get_caller(void)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007, Axel Dörfler, [email protected].
|
||||
* Copyright 2002-2008, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
@@ -519,9 +519,68 @@ dump_iframes(int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
is_calling(struct thread *thread, addr_t eip, const char *pattern,
|
||||
addr_t start, addr_t end)
|
||||
{
|
||||
if (pattern == NULL)
|
||||
return eip >= start && eip < end;
|
||||
|
||||
const char *symbol;
|
||||
if (lookup_symbol(thread, eip, NULL, &symbol, NULL, NULL) != B_OK)
|
||||
return false;
|
||||
|
||||
return strstr(symbol, pattern);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
bool
|
||||
arch_debug_contains_call(struct thread *thread, const char *symbol,
|
||||
addr_t start, addr_t end)
|
||||
{
|
||||
addr_t ebp;
|
||||
if (thread == thread_get_current_thread())
|
||||
ebp = x86_read_ebp();
|
||||
else
|
||||
ebp = thread->arch_info.current_stack.esp[2];
|
||||
|
||||
bool onKernelStack = true;
|
||||
|
||||
for (;;) {
|
||||
onKernelStack = onKernelStack
|
||||
&& is_kernel_stack_address(thread, ebp);
|
||||
|
||||
if (onKernelStack && is_iframe(thread, ebp)) {
|
||||
struct iframe *frame = (struct iframe *)ebp;
|
||||
|
||||
if (is_calling(thread, frame->eip, symbol, start, end))
|
||||
return true;
|
||||
|
||||
ebp = frame->ebp;
|
||||
} else {
|
||||
addr_t eip, nextEbp;
|
||||
|
||||
if (get_next_frame(ebp, &nextEbp, &eip) != B_OK
|
||||
|| eip == 0 || ebp == 0)
|
||||
break;
|
||||
|
||||
if (is_calling(thread, eip, symbol, start, end))
|
||||
return true;
|
||||
|
||||
ebp = nextEbp;
|
||||
}
|
||||
|
||||
if (ebp == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
arch_debug_get_caller(void)
|
||||
{
|
||||
@@ -541,8 +600,10 @@ arch_debug_init(kernel_args *args)
|
||||
|
||||
add_debugger_command("where", &stack_trace, "Same as \"sc\"");
|
||||
add_debugger_command("bt", &stack_trace, "Same as \"sc\" (as in gdb)");
|
||||
add_debugger_command("sc", &stack_trace, "Stack crawl for current thread (or any other)");
|
||||
add_debugger_command("iframe", &dump_iframes, "Dump iframes for the specified thread");
|
||||
add_debugger_command("sc", &stack_trace,
|
||||
"Stack crawl for current thread (or any other)");
|
||||
add_debugger_command("iframe", &dump_iframes,
|
||||
"Dump iframes for the specified thread");
|
||||
add_debugger_command("call", &show_call, "Show call with arguments");
|
||||
|
||||
return B_NO_ERROR;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <util/AutoLock.h>
|
||||
#include <util/khash.h>
|
||||
|
||||
#include <arch/debug.h>
|
||||
#include <boot/kernel_args.h>
|
||||
#include <condition_variable.h>
|
||||
#include <cpu.h>
|
||||
@@ -1121,6 +1122,10 @@ dump_thread_list(int argc, char **argv)
|
||||
struct thread *thread;
|
||||
struct hash_iterator i;
|
||||
bool realTimeOnly = false;
|
||||
bool calling = false;
|
||||
const char *callSymbol = NULL;
|
||||
addr_t callStart = 0;
|
||||
addr_t callEnd = 0;
|
||||
int32 requiredState = 0;
|
||||
team_id team = -1;
|
||||
sem_id sem = -1;
|
||||
@@ -1139,6 +1144,17 @@ dump_thread_list(int argc, char **argv)
|
||||
if (sem == 0)
|
||||
kprintf("ignoring invalid semaphore argument.\n");
|
||||
}
|
||||
} else if (!strcmp(argv[0], "calling")) {
|
||||
if (argc < 2) {
|
||||
kprintf("Need to give a symbol name or start and end arguments.\n");
|
||||
return 0;
|
||||
} else if (argc == 3) {
|
||||
callStart = parse_expression(argv[1]);
|
||||
callEnd = parse_expression(argv[2]);
|
||||
} else
|
||||
callSymbol = argv[1];
|
||||
|
||||
calling = true;
|
||||
} else if (argc > 1) {
|
||||
team = strtoul(argv[1], NULL, 0);
|
||||
if (team == 0)
|
||||
@@ -1152,6 +1168,8 @@ dump_thread_list(int argc, char **argv)
|
||||
while ((thread = (struct thread*)hash_next(sThreadHash, &i)) != NULL) {
|
||||
// filter out threads not matching the search criteria
|
||||
if ((requiredState && thread->state != requiredState)
|
||||
|| (calling && !arch_debug_contains_call(thread, callSymbol,
|
||||
callStart, callEnd))
|
||||
|| (sem > 0 && thread->sem.blocking != sem)
|
||||
|| (team > 0 && thread->team->id != team)
|
||||
|| (realTimeOnly && thread->priority < B_REAL_TIME_DISPLAY_PRIORITY))
|
||||
@@ -1978,6 +1996,9 @@ thread_init(kernel_args *args)
|
||||
" <id> - The ID of the thread.\n"
|
||||
" <address> - The address of the thread structure.\n"
|
||||
" <name> - The thread's name.\n", 0);
|
||||
add_debugger_command_etc("calling", &dump_thread_list,
|
||||
"Show all threads that have a specific address in their call chain",
|
||||
"{ <symbol-pattern> | <start> <end> }\n", 0);
|
||||
add_debugger_command_etc("unreal", &make_thread_unreal,
|
||||
"Set realtime priority threads to normal priority",
|
||||
"[ <id> ]\n"
|
||||
|
||||
Reference in New Issue
Block a user