gdb-python.diff 5.3 KB

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