OSDN Git Service

modified: utilsrc/src/Admin/Makefile
[eos/others.git] / utilsrc / srcX86MAC64 / Admin / gdb-7.7.1 / gdb / python / py-exitedevent.c
1 /* Python interface to inferior exit events.
2
3    Copyright (C) 2009-2014 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include "defs.h"
21 #include "py-event.h"
22
23 static PyTypeObject exited_event_object_type
24     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
25
26 static PyObject *
27 create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
28 {
29   PyObject *exited_event;
30   PyObject *inf_obj = NULL;
31
32   exited_event = create_event_object (&exited_event_object_type);
33
34   if (!exited_event)
35     goto fail;
36
37   if (exit_code)
38     {
39       PyObject *exit_code_obj = PyLong_FromLongLong (*exit_code);
40       int failed;
41
42       if (exit_code_obj == NULL)
43         goto fail;
44
45       failed = evpy_add_attribute (exited_event, "exit_code",
46                                    exit_code_obj) < 0;
47       Py_DECREF (exit_code_obj);
48       if (failed)
49         goto fail;
50     }
51
52   inf_obj = inferior_to_inferior_object (inf);
53   if (!inf_obj || evpy_add_attribute (exited_event,
54                                       "inferior",
55                                       inf_obj) < 0)
56     goto fail;
57   Py_DECREF (inf_obj);
58
59   return exited_event;
60
61  fail:
62   Py_XDECREF (inf_obj);
63   Py_XDECREF (exited_event);
64   return NULL;
65 }
66
67 /* Callback that is used when an exit event occurs.  This function
68    will create a new Python exited event object.  */
69
70 int
71 emit_exited_event (const LONGEST *exit_code, struct inferior *inf)
72 {
73   PyObject *event;
74
75   if (evregpy_no_listeners_p (gdb_py_events.exited))
76     return 0;
77
78   event = create_exited_event_object (exit_code, inf);
79
80   if (event)
81     return evpy_emit_event (event, gdb_py_events.exited);
82
83   return -1;
84 }
85
86
87 GDBPY_NEW_EVENT_TYPE (exited,
88                       "gdb.ExitedEvent",
89                       "ExitedEvent",
90                       "GDB exited event object",
91                       event_object_type,
92                       static);