From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4266 invoked by alias); 31 Jul 2007 13:35:58 -0000 Received: (qmail 4140 invoked by uid 22791); 31 Jul 2007 13:35:57 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 31 Jul 2007 13:35:52 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.1/8.13.1) with ESMTP id l6VDZoWx017481 for ; Tue, 31 Jul 2007 09:35:51 -0400 Received: from pobox.tokyo.redhat.com (pobox.tokyo.redhat.com [172.16.33.225]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l6VDZneg019254 for ; Tue, 31 Jul 2007 09:35:49 -0400 Received: from localhost (gps06.tokyo.redhat.com [172.16.32.89]) by pobox.tokyo.redhat.com (8.12.11.20060308/8.12.8) with ESMTP id l6VDZmjg011907 for ; Tue, 31 Jul 2007 22:35:48 +0900 Date: Tue, 31 Jul 2007 14:29:00 -0000 Message-Id: <20070731.223548.76561387.yamato@redhat.com> To: gdb-patches@sourceware.org Subject: To know the stopped reason from hook-stop From: Masatake YAMATO X-Mailer: Mew version 5.2 on Emacs 22.1.50 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00332.txt.bz2 (I am very new to this list. If my topic is suitable to this list, tell me the better list.) Is there way to know in hook-stop the reason why the execution is stopped? I could not find the way to do it, so I've just written a patch. The patch is far from complete, but I'd like to know how to improve it and integrate it to gdb official source tree. So I post the patch here. The reason is passed through with $arg. $arg0 is the number which represents the reason; $arg0 holds the number defined in gdb/target.h::target_waitkind. When I started working on this patch, I'd like to pass the reason in a string. However, I found that a string could not be used if the debuggee process was gone. So currently I'm using a number to represent the reason. With my patch you can do like this in your .gdbinit: define hook-stop # show stack trace only when the debuggee is # received a signal. if $arg0 == 1 where else quit end end Regards, Masatake YAMATO Index: gdb/command.h =================================================================== RCS file: /cvs/src/src/gdb/command.h,v retrieving revision 1.56 diff -u -r1.56 command.h --- gdb/command.h 9 Jan 2007 17:58:50 -0000 1.56 +++ gdb/command.h 31 Jul 2007 13:14:33 -0000 @@ -152,6 +152,7 @@ /* Execute CMD's pre/post hook. Throw an error if the command fails. If already executing this pre/post hook, or there is no pre/post hook, the call is silently ignored. */ +extern void execute_cmd_pre_hook_with_arg (struct cmd_list_element *cmd, char *arg); extern void execute_cmd_pre_hook (struct cmd_list_element *cmd); extern void execute_cmd_post_hook (struct cmd_list_element *cmd); Index: gdb/infrun.c =================================================================== RCS file: /cvs/src/src/gdb/infrun.c,v retrieving revision 1.244 diff -u -r1.244 infrun.c --- gdb/infrun.c 2 Jul 2007 21:29:27 -0000 1.244 +++ gdb/infrun.c 31 Jul 2007 13:14:34 -0000 @@ -3286,7 +3286,53 @@ static int hook_stop_stub (void *cmd) { - execute_cmd_pre_hook ((struct cmd_list_element *) cmd); + char args_buffer[128]; + struct target_waitstatus last; + ptid_t last_ptid; + + get_last_target_status (&last_ptid, &last); + + + args_buffer[0] = '\0'; + switch (last.kind) + { + case TARGET_WAITKIND_EXITED: + sprintf(args_buffer, "%d %s %d", last.kind, "exited", last.value.integer); + break; + case TARGET_WAITKIND_STOPPED: + sprintf(args_buffer, "%d %s %d", last.kind, "stopped", last.value.sig); + break; + case TARGET_WAITKIND_SIGNALLED: + sprintf(args_buffer, "%d %s %d", last.kind, "signalled", last.value.sig); + break; + case TARGET_WAITKIND_LOADED: + sprintf(args_buffer, "%d %s", last.kind, "loaded"); + break; + case TARGET_WAITKIND_FORKED: + sprintf(args_buffer, "%d %s %u", last.kind, "forked", last.value.related_pid); + break; + case TARGET_WAITKIND_VFORKED: + sprintf(args_buffer, "%d %s %u", last.kind, "vforked", last.value.related_pid); + break; + case TARGET_WAITKIND_EXECD: + // sprintf(args_buffer, "%s %s", "execd", value.execd_pathname); + break; + case TARGET_WAITKIND_SYSCALL_ENTRY: + sprintf(args_buffer, "%d %s %u", last.kind, "syscall_entry", last.value.syscall_id); + break; + case TARGET_WAITKIND_SYSCALL_RETURN: + sprintf(args_buffer, "%d %s %u", last.kind, "syscall_return", last.value.syscall_id); + break; + case TARGET_WAITKIND_SPURIOUS: + sprintf(args_buffer, "%d %s", last.kind, "spurious"); + break; + case TARGET_WAITKIND_IGNORE: + sprintf(args_buffer, "%d %s", last.kind, "ignore"); + break; + } + + execute_cmd_pre_hook_with_arg ((struct cmd_list_element *) cmd, + args_buffer); return (0); } cvs diff: Diffing gdb/cli Index: gdb/cli/cli-script.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-script.c,v retrieving revision 1.42 diff -u -r1.42 cli-script.c --- gdb/cli/cli-script.c 3 Jul 2007 01:23:01 -0000 1.42 +++ gdb/cli/cli-script.c 31 Jul 2007 13:14:34 -0000 @@ -242,18 +242,24 @@ } void -execute_cmd_pre_hook (struct cmd_list_element *c) +execute_cmd_pre_hook_with_arg (struct cmd_list_element *c, char *arg) { if ((c->hook_pre) && (!c->hook_in)) { struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c); c->hook_in = 1; /* Prevent recursive hooking */ - execute_user_command (c->hook_pre, (char *) 0); + execute_user_command (c->hook_pre, arg); do_cleanups (cleanups); } } void +execute_cmd_pre_hook (struct cmd_list_element *c) +{ + execute_cmd_pre_hook_with_arg(c, (char *)0); +} + +void execute_cmd_post_hook (struct cmd_list_element *c) { if ((c->hook_post) && (!c->hook_in))