For the past week, I have been trying to set debug breakpoints
within my program, completely without success. I am attempting
to debug a very evil and very pernicious memory problem by
setting watchpoints in such a way that gdb traps attempts to
write to certain structures on the heap. Would somebody please
take a look at the following code fragments and tell me what I'm
doing wrong?
/* This code returns an error every time I run it. I am trying to set
* a breakpoint that will stop the program when any unauthorized
* function alters the values of the structure at the head of the linked
* list.
*/
__dpmi_meminfo descriptor_list_watchpoint;
descriptor_list_watchpoint.address = (unsigned long)
&descriptor_list->next;
descriptor_list_watchpoint.size = sizeof(descriptor_list->next);
if ( __dpmi_set_debug_watchpoint( &descriptor_list_watchpoint, 1 ) )
bug( "Game_loop: set watchpoint failed at %#x",
descriptor_list_watchpoint.address );
/*This code doesn't error, but fails to set a working breakpoint. I
* am trying to set a means of breaking within the program without
* having to use Ctrl-C and without having to preset a breakpoint
* within gdb.
*/
void do_break( CHAR_DATA *ch, char *argument )
{
/* no code - triggers breakpoint */
send_to_char( "Breakpoint triggered.\n\r", ch );
return;
}
__dpmi_meminfo do_break_breakpoint =
{
0L, 4L, (unsigned long) do_break
};
[...]
/* in main() */
if ( __dpmi_set_debug_watchpoint( &do_break_breakpoint, 0 ) )
bug( "Main: set do_break breakpoint failed at %#x",
do_break_breakpoint.address );