Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / data / gdb / gdb-python.diff
1 diff --git a/gdb/ChangeLog b/gdb/ChangeLog
2 index 640998b..fb73e9d 100644
3 --- a/gdb/ChangeLog
4 +++ b/gdb/ChangeLog
5 @@ -1,3 +1,10 @@
6 +2009-02-03  Zoltan Varga  <vargaz@gmail.com>
7 +
8 +       * cil-script.c python/python-cmd.c: Allow registration of pre/post hooks from 
9 +       python.
10 +       
11 +       * symfile.c (add_symbol_file_command): Comment out verbose messages.
12 +
13  2009-02-03  Thiago Jung Bauermann  <bauerman@br.ibm.com>
14  
15         * gdb/c-lang.c (c_get_string): Remove superfluous parenthesis from
16 diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
17 index 835d29c..3941aa5 100644
18 --- a/gdb/cli/cli-script.c
19 +++ b/gdb/cli/cli-script.c
20 @@ -299,6 +299,13 @@ execute_user_command (struct cmd_list_element *c, char *args)
21    static int user_call_depth = 0;
22    extern int max_user_call_depth;
23  
24 +  /* Might be a user defined command implemented in Python */
25 +  if (!c->user_commands && c->func)
26 +       {
27 +         (*c->func) (c, args, FALSE);
28 +         return;
29 +       }
30 +       
31    old_chain = setup_user_args (args);
32  
33    cmdlines = c->user_commands;
34 diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c
35 index 61d5e5d..a3fbc08 100644
36 --- a/gdb/python/python-cmd.c
37 +++ b/gdb/python/python-cmd.c
38 @@ -339,7 +339,8 @@ gdbpy_parse_command_name (char *text, struct cmd_list_element ***base_list,
39  
40  /* Object initializer; sets up gdb-side structures for command.
41  
42 -   Use: __init__(NAME, CMDCLASS, [COMPLETERCLASS, [PREFIX]]).
43 +   Use: __init__(NAME, CMDCLASS, [completerclass=COMPLETERCLASS, prefix=PREFIX,
44 +                 pre_hook_of=PREHOOK_OF, post_hook_of=POSTHOOK_OF]).
45  
46     NAME is the name of the command.  It may consist of multiple words,
47     in which case the final word is the name of the new command, and
48 @@ -354,6 +355,11 @@ gdbpy_parse_command_name (char *text, struct cmd_list_element ***base_list,
49  
50     If PREFIX is True, then this command is a prefix command.
51  
52 +   PREHOOK_OF is the name of a gdb command this command becomes a 
53 +   pre-execution hook of, same as if this command was defined using 
54 +   "define hook-<cmdname>"
55 +   POSTHOOK_OF is the same for post-execution hooks.
56 +
57     The documentation for the command is taken from the doc string for
58     the python class.
59     
60 @@ -362,15 +368,18 @@ static int
61  cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
62  {
63    cmdpy_object *obj = (cmdpy_object *) self;
64 -  char *name;
65 +  char *name, *pre_hook_of = NULL, *post_hook_of = NULL;
66    int cmdtype;
67    int completetype = -1;
68    char *docstring = NULL;
69    volatile struct gdb_exception except;
70    struct cmd_list_element **cmd_list;
71 +  struct cmd_list_element *pre_hookc = NULL, *post_hookc = NULL;
72    char *cmd_name, *pfx_name;
73    PyObject *is_prefix = NULL;
74    int cmp;
75 +  static char *kwlist[] = {"name", "cmdclass", "completerclass", "prefix", 
76 +                                                  "pre_hook_of", "post_hook_of", NULL};
77  
78    if (obj->command)
79      {
80 @@ -381,8 +390,9 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
81        return -1;
82      }
83  
84 -  if (! PyArg_ParseTuple (args, "si|iO", &name, &cmdtype,
85 -                         &completetype, &is_prefix))
86 +  if (! PyArg_ParseTupleAndKeywords (args, kwds, "si|iOss", kwlist, &name, &cmdtype,
87 +                                                                        &completetype, &is_prefix, &pre_hook_of,
88 +                                                                        &post_hook_of))
89      return -1;
90  
91    if (cmdtype != no_class && cmdtype != class_run
92 @@ -402,6 +412,30 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
93        return -1;
94      }
95  
96 +  if (pre_hook_of)
97 +       {
98 +         char *text = pre_hook_of;
99 +
100 +         pre_hookc = lookup_cmd_1 (&text, cmdlist, NULL, 1);
101 +         if (! pre_hookc)
102 +               {
103 +                 PyErr_Format (PyExc_RuntimeError, _("command name given by pre_hook argument not found"));
104 +                 return -1;
105 +               }
106 +       }
107 +
108 +  if (post_hook_of)
109 +       {
110 +         char *text = post_hook_of;
111 +
112 +         post_hookc = lookup_cmd_1 (&text, cmdlist, NULL, 1);
113 +         if (! post_hookc)
114 +               {
115 +                 PyErr_Format (PyExc_RuntimeError, _("command name given by post_hook argument not found"));
116 +                 return -1;
117 +               }
118 +       }
119 +
120    cmd_name = gdbpy_parse_command_name (name, &cmd_list, &cmdlist);
121    if (! cmd_name)
122      return -1;
123 @@ -470,6 +504,18 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
124        cmd->func = cmdpy_function;
125        cmd->destroyer = cmdpy_destroyer;
126  
127 +         if (pre_hookc)
128 +               {
129 +                 pre_hookc->hook_pre = cmd;
130 +                 cmd->hookee_pre = pre_hookc;
131 +               }
132 +
133 +         if (post_hookc)
134 +               {
135 +                 post_hookc->hook_post = cmd;
136 +                 cmd->hookee_post = post_hookc;
137 +               }
138 +
139        obj->command = cmd;
140        set_cmd_context (cmd, self);
141        set_cmd_completer (cmd, ((completetype == -1) ? cmdpy_completer
142 diff --git a/gdb/symfile.c b/gdb/symfile.c
143 index 14cb7b8..6d0bb40 100644
144 --- a/gdb/symfile.c
145 +++ b/gdb/symfile.c
146 @@ -2196,7 +2196,7 @@ add_symbol_file_command (char *args, int from_tty)
147       statements because hex_string returns a local static
148       string. */
149  
150 -  printf_unfiltered (_("add symbol table from file \"%s\" at\n"), filename);
151 +  /* printf_unfiltered (_("add symbol table from file \"%s\" at\n"), filename); */
152    section_addrs = alloc_section_addr_info (section_index);
153    make_cleanup (xfree, section_addrs);
154    for (i = 0; i < section_index; i++)
155 @@ -2211,7 +2211,7 @@ add_symbol_file_command (char *args, int from_tty)
156           entered on the command line. */
157        section_addrs->other[sec_num].name = sec;
158        section_addrs->other[sec_num].addr = addr;
159 -      printf_unfiltered ("\t%s_addr = %s\n", sec, paddress (addr));
160 +      /* printf_unfiltered ("\t%s_addr = %s\n", sec, paddress (addr)); */
161        sec_num++;
162  
163        /* The object's sections are initialized when a