2007-05-17 05:37:49 +02:00
|
|
|
/* udbg.cpp
|
|
|
|
|
|
|
|
This file contains debug helpers that are common for all unix systems. See
|
|
|
|
udbg_bfd.cpp for the linux-specific stuff (Using BFD and backtrace() for symbol
|
|
|
|
lookups and backtraces)
|
|
|
|
*/
|
|
|
|
|
2004-07-13 00:05:49 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "lib/timer.h"
|
|
|
|
#include "lib/sysdep/sysdep.h"
|
|
|
|
#include "lib/debug.h"
|
2004-07-13 00:05:49 +02:00
|
|
|
|
2007-05-17 05:37:49 +02:00
|
|
|
#if !OS_LINUX
|
|
|
|
// udbg stubs implementation. This is what's used on non-linux, so far.
|
|
|
|
void* debug_get_nth_caller(uint UNUSED(n), void *UNUSED(context))
|
2005-02-02 18:01:33 +01:00
|
|
|
{
|
2007-05-17 05:37:49 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-02-02 18:01:33 +01:00
|
|
|
|
2007-05-17 05:37:49 +02:00
|
|
|
LibError debug_dump_stack(wchar_t* UNUSED(buf), size_t UNUSED(max_chars), uint UNUSED(skip), void* UNUSED(context))
|
2005-02-02 18:01:33 +01:00
|
|
|
{
|
2007-05-17 05:37:49 +02:00
|
|
|
return ERR::NOT_IMPLEMENTED;
|
|
|
|
}
|
2005-02-02 18:01:33 +01:00
|
|
|
|
2007-05-17 05:37:49 +02:00
|
|
|
LibError debug_resolve_symbol(void* UNUSED(ptr_of_interest), char* UNUSED(sym_name), char* UNUSED(file), int* UNUSED(line))
|
|
|
|
{
|
|
|
|
return ERR::NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
#endif
|
2005-02-02 18:01:33 +01:00
|
|
|
|
2004-07-13 00:05:49 +02:00
|
|
|
void unix_debug_break()
|
|
|
|
{
|
|
|
|
kill(getpid(), SIGTRAP);
|
|
|
|
}
|
2004-07-14 14:24:18 +02:00
|
|
|
|
2007-05-17 05:37:49 +02:00
|
|
|
#define DEBUGGER_WAIT 3
|
|
|
|
#define DEBUGGER_CMD "gdb"
|
|
|
|
#define DEBUGGER_ARG_FORMAT "--pid=%d"
|
|
|
|
#define DEBUGGER_BREAK_AFTER_WAIT 0
|
|
|
|
|
2004-07-14 14:24:18 +02:00
|
|
|
/*
|
|
|
|
Start the debugger and tell it to attach to the current process/thread
|
2005-06-21 18:48:09 +02:00
|
|
|
(called by display_error)
|
2004-07-14 14:24:18 +02:00
|
|
|
*/
|
2005-06-21 18:48:09 +02:00
|
|
|
void udbg_launch_debugger()
|
2004-07-14 14:24:18 +02:00
|
|
|
{
|
|
|
|
pid_t orgpid=getpid();
|
|
|
|
pid_t ret=fork();
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
// Child Process: exec() gdb (Debugger), set to attach to old fork
|
|
|
|
char buf[16];
|
|
|
|
snprintf(buf, 16, DEBUGGER_ARG_FORMAT, orgpid);
|
|
|
|
|
|
|
|
int ret=execlp(DEBUGGER_CMD, DEBUGGER_CMD, buf, NULL);
|
|
|
|
// In case of success, we should never get here anyway, though...
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
perror("Debugger launch failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ret > 0)
|
|
|
|
{
|
|
|
|
// Parent (original) fork:
|
2006-11-12 05:02:36 +01:00
|
|
|
debug_printf("Sleeping until debugger attaches.\nPlease wait.\n");
|
2004-07-14 14:24:18 +02:00
|
|
|
sleep(DEBUGGER_WAIT);
|
|
|
|
}
|
|
|
|
else // fork error, ret == -1
|
|
|
|
{
|
|
|
|
perror("Debugger launch: fork failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-24 01:57:59 +02:00
|
|
|
void debug_puts(const char* text)
|
2004-07-15 21:59:27 +02:00
|
|
|
{
|
2005-10-24 01:57:59 +02:00
|
|
|
fputs(text, stdout);
|
2005-06-22 05:23:22 +02:00
|
|
|
fflush(stdout);
|
2004-07-15 21:59:27 +02:00
|
|
|
}
|
2005-05-12 00:49:01 +02:00
|
|
|
|
2005-06-22 05:23:22 +02:00
|
|
|
// TODO: Do these properly. (I don't know what I'm doing; I just
|
|
|
|
// know that these functions are required in order to compile...)
|
2005-05-12 00:49:01 +02:00
|
|
|
|
2006-01-29 19:23:47 +01:00
|
|
|
int debug_write_crashlog(const char* UNUSED(file), wchar_t* UNUSED(header),
|
|
|
|
void* UNUSED(context))
|
2005-05-12 00:49:01 +02:00
|
|
|
{
|
2005-06-22 05:23:22 +02:00
|
|
|
abort();
|
2005-05-12 00:49:01 +02:00
|
|
|
}
|
|
|
|
|
2006-01-29 19:23:47 +01:00
|
|
|
int debug_is_pointer_bogus(const void* UNUSED(p))
|
2005-08-07 23:58:36 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-22 05:23:22 +02:00
|
|
|
|
|
|
|
void debug_heap_check()
|
2005-05-12 00:49:01 +02:00
|
|
|
{
|
2005-05-18 07:32:09 +02:00
|
|
|
}
|
2005-06-21 18:48:09 +02:00
|
|
|
|
2005-06-22 05:23:22 +02:00
|
|
|
// if <full_monty> is true or PARANOIA #defined, all possible checks are
|
|
|
|
// performed as often as possible. this is really slow (we are talking x100),
|
|
|
|
// but reports errors closer to where they occurred.
|
2006-01-29 19:23:47 +01:00
|
|
|
void debug_heap_enable(DebugHeapChecks UNUSED(what))
|
2005-06-21 18:48:09 +02:00
|
|
|
{
|
2005-08-07 23:58:36 +02:00
|
|
|
// No-op until we find out if glibc has heap debugging
|
2005-06-22 05:23:22 +02:00
|
|
|
}
|
2005-06-21 18:48:09 +02:00
|
|
|
|
2005-06-22 05:23:22 +02:00
|
|
|
// disable all automatic checks until the next debug_heap_enable.
|
|
|
|
void debug_heap_disable()
|
|
|
|
{
|
2006-01-29 19:23:47 +01:00
|
|
|
// No-op until we find out if glibc has heap debugging
|
2005-06-21 18:48:09 +02:00
|
|
|
}
|