From: Davide Libenzi <davidel@xmailserver.org>
To: Tony Hoyle <tmh@nothing-on.tv>
Cc: linux-kernel@vger.kernel.org
Subject: RE: just-in-time debugging?
Date: Sat, 28 Apr 2001 13:44:48 -0700 (PDT) [thread overview]
Message-ID: <XFMail.20010428134448.davidel@xmailserver.org> (raw)
In-Reply-To: <20010428201708.E629E13F6A@mail.cvsnt.org>
[-- Attachment #1: Type: text/plain, Size: 1236 bytes --]
On 28-Apr-2001 Tony Hoyle wrote:
> Is there a way (kernel or userspace... doesn't matter) that gdb/ddd
> could be invoked when a program is about
> to dump core, or perhaps on a certain signal (that the app could deliver
> to itself when required). The latter case
> is what I need right now, as I have to debug an app that breaks
> seemingly randomly & I need to halt when
> certain assertions fail. Core dumps aren't much use as you can't resume
> them, otherwise I'd just force a segfault
> or something.
>
> I had a look at the do_coredump stuff and it looks like it could be
> altered to call gdb in the same way that
> modprobe gets called by kmod... however I don't sufficiently know the
> code to work out whether it'd work properly
> or not.
Sorry but why don't You run Your application with gdb ?
Once Your program crashes You'll get the prompt and You'll be able to
stack-trace and watching whatever You need.
The solution I use to be able to get inside the program even when the gdb is
not running is the one that You can find in the attached file.
Basically it install the handler that will create a script file that You can
use to automatically enter with gdb inside Your program while it's running.
- Davide
[-- Attachment #2: GdbHook.cpp --]
[-- Type: application/octet-stream, Size: 3918 bytes --]
#define GDBHOOK_DEBUGGER "gdb"
#define GDBHOOK_MODE "GDBHOOK_MODE"
#define GDBHOOK_BELL_COUNT "GDBHOOK_BELL_COUNT"
#define GDBHOOK_STD_BELL_COUNT 4
#define GDBHOOK_STDPREFIX "sig-hook"
#define GDBHOOK_WAIT "GDBHOOK_WAIT"
#define GDBHOOK_STD_WAIT 4
static int
DbghWaitProc(char const * pszFileName);
static void
DbghSigHandler(int iSignal);
static int
DbghCleanupFiles(char const * pszPath);
static char szProgram[256] = "",
szPath[256] = "";
static int
DbghWaitProc(char const * pszFileName)
{
char const * pszBellCnt = getenv(GDBHOOK_BELL_COUNT);
int iBellCnt = (pszBellCnt != NULL) ? atoi(pszBellCnt): GDBHOOK_STD_BELL_COUNT;
char const * pszWait = getenv(GDBHOOK_WAIT);
int iWait = (pszWait != NULL) ? atoi(pszWait): GDBHOOK_STD_WAIT;
volatile int iLoop = 0;
while (!iLoop && (access(pszFileName, F_OK) == 0))
{
if (iBellCnt > 0)
fprintf(stderr, "%c", 7), --iBellCnt;
sleep(iWait);
}
return (0);
}
static void
DbghSigHandler(int iSignal)
{
char const * pszEnvVar = getenv(GDBHOOK_MODE);
if ((pszEnvVar != NULL) && atoi(pszEnvVar))
{
char szDbgFile[256] = "";
sprintf(szDbgFile, "%s%s.%d.%u.hook", szPath, GDBHOOK_STDPREFIX, iSignal, getpid());
FILE * pFile = fopen(szDbgFile, "w");
if (pFile != NULL)
{
time_t tFault = time(NULL);
#ifdef SOLARIS
fprintf(pFile,
"#!/bin/sh\n"
"#\n"
"# Signal = %s (%d)\n"
"# Time = %s"
"# Pid = %u\n"
"#\n"
"%s %s %u\n\n",
(iSignal < _sys_nsig) ? _sys_siglist[iSignal]: "????", iSignal, ctime(&tFault),
getpid(), GDBHOOK_DEBUGGER, szProgram, getpid());
#else // #ifdef SOLARIS
fprintf(pFile,
"#!/bin/sh\n"
"#\n"
"# Signal = %s (%d)\n"
"# Time = %s"
"# Pid = %u\n"
"#\n"
"%s %s %u\n\n",
(iSignal < _NSIG) ? _sys_siglist[iSignal]: "????", iSignal, ctime(&tFault),
getpid(), GDBHOOK_DEBUGGER, szProgram, getpid());
#endif // #ifdef SOLARIS
fclose(pFile);
chmod(szDbgFile, 0755);
DbghWaitProc(szDbgFile);
signal(iSignal, SIG_DFL);
}
}
else
signal(iSignal, SIG_DFL);
}
static int
DbghCleanupFiles(char const * pszPath)
{
glob_t globbuf;
char szPattern[256] = "";
sprintf(szPattern, "%s*.hook", pszPath);
if (glob(szPattern, 0, NULL, &globbuf) == 0)
{
for (int ii = 0; ii < globbuf.gl_pathc; ii++)
unlink(globbuf.gl_pathv[ii]);
}
globfree(&globbuf);
return (0);
}
int
DbghInit(char const * pszProgram)
{
strcpy(szProgram, pszProgram);
char const * pszSlash = strrchr(pszProgram, '/');
if (pszSlash != NULL)
{
int iPathLength = (int) (pszSlash - pszProgram) + 1;
strncpy(szPath, pszProgram, iPathLength);
szPath[iPathLength] = '\0';
}
else
strcpy(szPath, "./");
if (DbghCleanupFiles(szPath) < 0)
return (-1);
return (0);
}
int
DbghInstall(void)
{
signal(SIGSEGV, DbghSigHandler);
signal(SIGBUS, DbghSigHandler);
signal(SIGFPE, DbghSigHandler);
#ifdef LINUX
signal(SIGSTKFLT, DbghSigHandler);
#endif // #ifdef LINUX
signal(SIGABRT, DbghSigHandler);
return (0);
}
int
DbghWaitPoint(char const * pszName)
{
char const * pszEnvVar = getenv(GDBHOOK_MODE);
if ((pszEnvVar != NULL) && atoi(pszEnvVar))
{
char szDbgFile[256] = "";
sprintf(szDbgFile, "%s%s.%u.hook", szPath, pszName, getpid());
FILE * pFile = fopen(szDbgFile, "w");
if (pFile != NULL)
{
time_t tFault = time(NULL);
fprintf(pFile,
"#!/bin/sh\n"
"#\n"
"# Time = %s"
"# Pid = %u\n"
"#\n"
"%s %s %u\n\n",
ctime(&tFault), getpid(), GDBHOOK_DEBUGGER, szProgram, getpid());
fclose(pFile);
chmod(szDbgFile, 0755);
DbghWaitProc(szDbgFile);
}
}
return (0);
}
int
DbghCleanup(void)
{
return (0);
}
next prev parent reply other threads:[~2001-04-28 20:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-28 20:17 just-in-time debugging? Tony Hoyle
2001-04-28 20:44 ` Davide Libenzi [this message]
2001-04-28 21:00 ` Tony Hoyle
2001-04-28 21:06 ` Davide Libenzi
2001-05-01 7:25 ` Sean Hunter
-- strict thread matches above, loose matches on Subject: below --
2001-04-28 20:42 Dan Kegel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=XFMail.20010428134448.davidel@xmailserver.org \
--to=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tmh@nothing-on.tv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox