RE: just-in-time debugging?

Davide Libenzi (davidel@xmailserver.org)
Sat, 28 Apr 2001 13:44:48 -0700 (PDT)


This message is in MIME format
--_=XFMail.1.4.7.Linux:20010428134448:1130=_
Content-Type: text/plain; charset=us-ascii

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

--_=XFMail.1.4.7.Linux:20010428134448:1130=_
Content-Disposition: attachment; filename="GdbHook.cpp"
Content-Transfer-Encoding: base64
Content-Description: GdbHook.cpp
Content-Type: application/octet-stream; name=GdbHook.cpp; SizeOnDisk=3918

CgoKCgoKI2RlZmluZSBHREJIT09LX0RFQlVHR0VSCQkJImdkYiIKI2RlZmluZSBHREJIT09LX01P
REUJCQkJIkdEQkhPT0tfTU9ERSIKI2RlZmluZSBHREJIT09LX0JFTExfQ09VTlQJCQkiR0RCSE9P
S19CRUxMX0NPVU5UIgojZGVmaW5lIEdEQkhPT0tfU1REX0JFTExfQ09VTlQJCTQKI2RlZmluZSBH
REJIT09LX1NURFBSRUZJWAkJCSJzaWctaG9vayIKI2RlZmluZSBHREJIT09LX1dBSVQJCQkJIkdE
QkhPT0tfV0FJVCIKI2RlZmluZSBHREJIT09LX1NURF9XQUlUCQkJNAoKCgoKCgoKCgpzdGF0aWMg
aW50Ck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xlLCAidyIpOwoKCQlpZiAocEZpbGUgIT0g
TlVMTCkKCQl7CgkJCXRpbWVfdAl0RmF1bHQgPSB0aW1lKE5VTEwpOwoKCQkJZnByaW50ZihwRmls
ZSwKICAgCQkJCQkiIyEvYmluL3NoXG4iCiAgIAkJCQkJIiNcbiIKICAgCQkJCQkiIyBUaW1lICAg
PSAlcyIKICAgCQkJCQkiIyBQaWQgICAgPSAldVxuIgogICAJCQkJCSIjXG4iCiAgIAkJCQkJIiVz
ICVzICV1XG5cbiIsCiAgIAkJCQkJY3RpbWUoJnRGYXVsdCksIGdldHBpZCgpLCBHREJIT09LX0RF
QlVHR0VSLCBzelByb2dyYW0sIGdldHBpZCgpKTsKICAgCQogICAJCQlmY2xvc2UocEZpbGUpOwoK
ICAgCQkJCiAgIAkJCWNobW9kKHN6RGJnRmlsZSwgMDc1NSk7CgogICAJCQkKICAgCQkJRGJnaFdh
aXRQcm9jKHN6RGJnRmlsZSk7CiAgIAkJCQoJICAgCX0KCX0KCglyZXR1cm4gKDApOwoKfQoKCgpp
bnQKRGJnaENsZWFudXAodm9pZCkKewoKCglyZXR1cm4gKDApOwoKfQoK

--_=XFMail.1.4.7.Linux:20010428134448:1130=_--
End of MIME message
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/