* Debugger modules now have two methods: enter_debugger() and exit_debugger().
* The kernel now opens up to 8 debugger modules (and puts them into an array; maybe we'll want to switch to a doubly linked list when there is the need). * Implemented an example debugger module that prints a stack trace of the current thread when the kernel debugger is entered (not included in the image). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23794 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -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 Haiku License.
|
* Distributed under the terms of the Haiku License.
|
||||||
*
|
*
|
||||||
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
|
#include <module.h>
|
||||||
|
|
||||||
|
|
||||||
#define KDEBUG 1
|
#define KDEBUG 1
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@
|
|||||||
* The kernel debug level.
|
* The kernel debug level.
|
||||||
* Level 1 is usual asserts, > 1 should be used for very expensive runtime checks
|
* Level 1 is usual asserts, > 1 should be used for very expensive runtime checks
|
||||||
*/
|
*/
|
||||||
#define KDEBUG 1
|
# define KDEBUG 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASSERT_ALWAYS(x) \
|
#define ASSERT_ALWAYS(x) \
|
||||||
@@ -42,6 +44,13 @@
|
|||||||
|
|
||||||
#define B_KDEBUG_DONT_PARSE_ARGUMENTS (0x01)
|
#define B_KDEBUG_DONT_PARSE_ARGUMENTS (0x01)
|
||||||
|
|
||||||
|
struct debugger_module_info {
|
||||||
|
module_info info;
|
||||||
|
|
||||||
|
void (*enter_debugger)(void);
|
||||||
|
void (*exit_debugger)(void);
|
||||||
|
};
|
||||||
|
|
||||||
extern int dbg_register_file[B_MAX_CPU_COUNT][14];
|
extern int dbg_register_file[B_MAX_CPU_COUNT][14];
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
SubDir HAIKU_TOP src add-ons kernel debugger ;
|
SubDir HAIKU_TOP src add-ons kernel debugger ;
|
||||||
|
|
||||||
|
SubInclude HAIKU_TOP src add-ons kernel debugger auto_stack_trace ;
|
||||||
SubInclude HAIKU_TOP src add-ons kernel debugger hangman ;
|
SubInclude HAIKU_TOP src add-ons kernel debugger hangman ;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
SubDir HAIKU_TOP src add-ons kernel debugger auto_stack_trace ;
|
||||||
|
|
||||||
|
UsePrivateHeaders kernel ;
|
||||||
|
|
||||||
|
KernelAddon <kdebug>auto_stack_trace :
|
||||||
|
auto_stack_trace.cpp
|
||||||
|
;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008, Axel Dörfler, [email protected]
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
enter_debugger(void)
|
||||||
|
{
|
||||||
|
evaluate_debug_command("sc");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static status_t
|
||||||
|
std_ops(int32 op, ...)
|
||||||
|
{
|
||||||
|
if (op == B_MODULE_INIT || op == B_MODULE_UNINIT)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct debugger_module_info sModuleInfo = {
|
||||||
|
{
|
||||||
|
"debugger/auto_stack_trace/v1",
|
||||||
|
0,
|
||||||
|
&std_ops
|
||||||
|
},
|
||||||
|
enter_debugger,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
module_info *modules[] = {
|
||||||
|
(module_info *)&sModuleInfo,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ SubDir HAIKU_TOP src add-ons kernel debugger hangman ;
|
|||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||||
|
|
||||||
# UsePrivateHeaders drivers ;
|
# UsePrivateHeaders drivers ;
|
||||||
# UsePrivateHeaders kernel ;
|
UsePrivateHeaders kernel ;
|
||||||
|
|
||||||
|
|
||||||
KernelAddon <kdebug>hangman :
|
KernelAddon <kdebug>hangman :
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#ifdef _KERNEL_MODE
|
#ifdef _KERNEL_MODE
|
||||||
#include <Drivers.h>
|
# include <Drivers.h>
|
||||||
#include <KernelExport.h>
|
# include <KernelExport.h>
|
||||||
#include <module.h>
|
# include <module.h>
|
||||||
|
# include <debug.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <image.h>
|
#include <image.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -440,37 +442,44 @@ find_device(const char *name)
|
|||||||
# else /* as module */
|
# else /* as module */
|
||||||
|
|
||||||
|
|
||||||
status_t std_ops(int32 op, ...);
|
static status_t
|
||||||
|
|
||||||
status_t
|
|
||||||
std_ops(int32 op, ...)
|
std_ops(int32 op, ...)
|
||||||
{
|
{
|
||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case B_MODULE_INIT:
|
case B_MODULE_INIT:
|
||||||
err = init_words(FORTUNE_FILE);
|
err = init_words(FORTUNE_FILE);
|
||||||
if (err < B_OK) {
|
if (err < B_OK) {
|
||||||
dprintf("hangman: error reading fortune file: %s\n", strerror(err));
|
dprintf("hangman: error reading fortune file: %s\n",
|
||||||
return B_ERROR;
|
strerror(err));
|
||||||
}
|
return B_ERROR;
|
||||||
add_debugger_command("kdlhangman", kdlhangman, KCMD_HELP);
|
}
|
||||||
return B_OK;
|
add_debugger_command("kdlhangman", kdlhangman, KCMD_HELP);
|
||||||
case B_MODULE_UNINIT:
|
return B_OK;
|
||||||
remove_debugger_command("kdlhangman", kdlhangman);
|
case B_MODULE_UNINIT:
|
||||||
return B_ERROR;
|
remove_debugger_command("kdlhangman", kdlhangman);
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static module_info minfo = {
|
static struct debugger_module_info sModuleInfo = {
|
||||||
"debugger/hangman/v1",
|
{
|
||||||
B_KEEP_LOADED,
|
"debugger/hangman/v1",
|
||||||
&std_ops
|
B_KEEP_LOADED,
|
||||||
|
&std_ops
|
||||||
|
},
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
module_info *modules[] = { &minfo, NULL };
|
module_info *modules[] = {
|
||||||
|
(module_info *)&sModuleInfo,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
# endif /* AS_DRIVER */
|
# endif /* AS_DRIVER */
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||||
@@ -74,6 +74,10 @@ static int64 sMessageRepeatFirstTime = 0;
|
|||||||
static int64 sMessageRepeatLastTime = 0;
|
static int64 sMessageRepeatLastTime = 0;
|
||||||
static int32 sMessageRepeatCount = 0;
|
static int32 sMessageRepeatCount = 0;
|
||||||
|
|
||||||
|
static debugger_module_info *sDebuggerModules[8];
|
||||||
|
static const uint32 kMaxDebuggerModules = sizeof(sDebuggerModules)
|
||||||
|
/ sizeof(sDebuggerModules[0]);
|
||||||
|
|
||||||
#define LINE_BUFFER_SIZE 1024
|
#define LINE_BUFFER_SIZE 1024
|
||||||
#define HISTORY_SIZE 16
|
#define HISTORY_SIZE 16
|
||||||
|
|
||||||
@@ -850,6 +854,23 @@ err1:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
call_modules_hook(bool enter)
|
||||||
|
{
|
||||||
|
uint32 index = 0;
|
||||||
|
while (index < kMaxDebuggerModules && sDebuggerModules[index] != NULL) {
|
||||||
|
debugger_module_info *module = sDebuggerModules[index];
|
||||||
|
|
||||||
|
if (enter && module->enter_debugger != NULL)
|
||||||
|
module->enter_debugger();
|
||||||
|
else if (!enter && module->exit_debugger != NULL)
|
||||||
|
module->exit_debugger();
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - private kernel API
|
// #pragma mark - private kernel API
|
||||||
|
|
||||||
|
|
||||||
@@ -995,17 +1016,19 @@ debug_init_post_modules(struct kernel_args *args)
|
|||||||
|
|
||||||
// load kernel debugger addons
|
// load kernel debugger addons
|
||||||
cookie = open_module_list("debugger");
|
cookie = open_module_list("debugger");
|
||||||
while (true) {
|
uint32 count = 0;
|
||||||
|
while (count < kMaxDebuggerModules) {
|
||||||
char name[B_FILE_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
size_t nameLength = sizeof(name);
|
size_t nameLength = sizeof(name);
|
||||||
module_info *module;
|
|
||||||
|
|
||||||
if (read_next_module_name(cookie, name, &nameLength) != B_OK)
|
if (read_next_module_name(cookie, name, &nameLength) != B_OK)
|
||||||
break;
|
break;
|
||||||
if (get_module(name, &module) == B_OK)
|
|
||||||
dprintf("kernel debugger extention \"%s\": loaded\n", name);
|
if (get_module(name, (module_info **)&sDebuggerModules[count]) == B_OK) {
|
||||||
else
|
dprintf("kernel debugger extension \"%s\": loaded\n", name);
|
||||||
dprintf("kernel debugger extention \"%s\": failed to load\n", name);
|
count++;
|
||||||
|
} else
|
||||||
|
dprintf("kernel debugger extension \"%s\": failed to load\n", name);
|
||||||
}
|
}
|
||||||
close_module_list(cookie);
|
close_module_list(cookie);
|
||||||
|
|
||||||
@@ -1093,8 +1116,11 @@ kernel_debugger(const char *message)
|
|||||||
// sort the commands
|
// sort the commands
|
||||||
sort_debugger_commands();
|
sort_debugger_commands();
|
||||||
|
|
||||||
|
call_modules_hook(true);
|
||||||
|
|
||||||
kernel_debugger_loop();
|
kernel_debugger_loop();
|
||||||
|
|
||||||
|
call_modules_hook(false);
|
||||||
set_dprintf_enabled(dprintfState);
|
set_dprintf_enabled(dprintfState);
|
||||||
|
|
||||||
sBlueScreenEnabled = false;
|
sBlueScreenEnabled = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user