interps.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* Manages interpreters for GDB, the GNU debugger.
  2. Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. Written by Jim Ingham <jingham@apple.com> of Apple Computer, Inc.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef INTERPS_H
  16. #define INTERPS_H
  17. struct ui_out;
  18. struct interp;
  19. struct ui;
  20. class completion_tracker;
  21. typedef struct interp *(*interp_factory_func) (const char *name);
  22. /* Each interpreter kind (CLI, MI, etc.) registers itself with a call
  23. to this function, passing along its name, and a pointer to a
  24. function that creates a new instance of an interpreter with that
  25. name. */
  26. extern void interp_factory_register (const char *name,
  27. interp_factory_func func);
  28. extern struct gdb_exception interp_exec (struct interp *interp,
  29. const char *command);
  30. class interp
  31. {
  32. public:
  33. explicit interp (const char *name);
  34. virtual ~interp () = 0;
  35. virtual void init (bool top_level)
  36. {}
  37. virtual void resume () = 0;
  38. virtual void suspend () = 0;
  39. virtual gdb_exception exec (const char *command) = 0;
  40. /* Returns the ui_out currently used to collect results for this
  41. interpreter. It can be a formatter for stdout, as is the case
  42. for the console & mi outputs, or it might be a result
  43. formatter. */
  44. virtual ui_out *interp_ui_out () = 0;
  45. /* Provides a hook for interpreters to do any additional
  46. setup/cleanup that they might need when logging is enabled or
  47. disabled. */
  48. virtual void set_logging (ui_file_up logfile, bool logging_redirect,
  49. bool debug_redirect) = 0;
  50. /* Called before starting an event loop, to give the interpreter a
  51. chance to e.g., print a prompt. */
  52. virtual void pre_command_loop ()
  53. {}
  54. /* Returns true if this interpreter supports using the readline
  55. library; false if it uses GDB's own simplified readline
  56. emulation. */
  57. virtual bool supports_command_editing ()
  58. { return false; }
  59. const char *name () const
  60. {
  61. return m_name;
  62. }
  63. /* This is the name in "-i=" and "set interpreter". */
  64. private:
  65. char *m_name;
  66. /* Interpreters are stored in a linked list, this is the next
  67. one... */
  68. public:
  69. struct interp *next;
  70. /* Has the init method been run? */
  71. bool inited;
  72. };
  73. /* Look up the interpreter for NAME, creating one if none exists yet.
  74. If NAME is not a interpreter type previously registered with
  75. interp_factory_register, return NULL; otherwise return a pointer to
  76. the interpreter. */
  77. extern struct interp *interp_lookup (struct ui *ui, const char *name);
  78. /* Set the current UI's top level interpreter to the interpreter named
  79. NAME. Throws an error if NAME is not a known interpreter or the
  80. interpreter fails to initialize. */
  81. extern void set_top_level_interpreter (const char *name);
  82. /* Temporarily set the current interpreter, and reset it on
  83. destruction. */
  84. class scoped_restore_interp
  85. {
  86. public:
  87. scoped_restore_interp (const char *name)
  88. : m_interp (set_interp (name))
  89. {
  90. }
  91. ~scoped_restore_interp ()
  92. {
  93. set_interp (m_interp->name ());
  94. }
  95. scoped_restore_interp (const scoped_restore_interp &) = delete;
  96. scoped_restore_interp &operator= (const scoped_restore_interp &) = delete;
  97. private:
  98. struct interp *set_interp (const char *name);
  99. struct interp *m_interp;
  100. };
  101. extern int current_interp_named_p (const char *name);
  102. /* Call this function to give the current interpreter an opportunity
  103. to do any special handling of streams when logging is enabled or
  104. disabled. LOGFILE is the stream for the log file when logging is
  105. starting and is NULL when logging is ending. LOGGING_REDIRECT is
  106. the value of the "set logging redirect" setting. If true, the
  107. interpreter should configure the output streams to send output only
  108. to the logfile. If false, the interpreter should configure the
  109. output streams to send output to both the current output stream
  110. (i.e., the terminal) and the log file. DEBUG_REDIRECT is same as
  111. LOGGING_REDIRECT, but for the value of "set logging debugredirect"
  112. instead. */
  113. extern void current_interp_set_logging (ui_file_up logfile,
  114. bool logging_redirect,
  115. bool debug_redirect);
  116. /* Returns the top-level interpreter. */
  117. extern struct interp *top_level_interpreter (void);
  118. /* Return the current UI's current interpreter. */
  119. extern struct interp *current_interpreter (void);
  120. extern struct interp *command_interp (void);
  121. extern void clear_interpreter_hooks (void);
  122. /* Returns true if INTERP supports using the readline library; false
  123. if it uses GDB's own simplified form of readline. */
  124. extern int interp_supports_command_editing (struct interp *interp);
  125. /* Called before starting an event loop, to give the interpreter a
  126. chance to e.g., print a prompt. */
  127. extern void interp_pre_command_loop (struct interp *interp);
  128. /* List the possible interpreters which could complete the given
  129. text. */
  130. extern void interpreter_completer (struct cmd_list_element *ignore,
  131. completion_tracker &tracker,
  132. const char *text,
  133. const char *word);
  134. /* well-known interpreters */
  135. #define INTERP_CONSOLE "console"
  136. #define INTERP_MI1 "mi1"
  137. #define INTERP_MI2 "mi2"
  138. #define INTERP_MI3 "mi3"
  139. #define INTERP_MI "mi"
  140. #define INTERP_TUI "tui"
  141. #define INTERP_INSIGHT "insight"
  142. #endif