1 # Extended prompt utilities.
2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 """ Extended prompt library functions."""
22 def _prompt_pwd(ignore):
23 "The current working directory."
26 def _prompt_object_attr(func, what, attr, nattr):
27 """Internal worker for fetching GDB attributes."""
33 return '<no %s>' % what
34 if hasattr(obj, attr):
35 result = getattr(obj, attr)
40 return '<no attribute %s on current %s>' % (attr, what)
42 def _prompt_frame(attr):
43 "The selected frame; an argument names a frame parameter."
44 return _prompt_object_attr(gdb.selected_frame, 'frame', attr, 'name')
46 def _prompt_thread(attr):
47 "The selected thread; an argument names a thread parameter."
48 return _prompt_object_attr(gdb.selected_thread, 'thread', attr, 'num')
50 def _prompt_version(attr):
54 def _prompt_esc(attr):
70 def _prompt_param(attr):
71 "A parameter's value; the argument names the parameter."
72 return gdb.parameter(attr)
74 def _prompt_noprint_begin(attr):
75 "Begins a sequence of non-printing characters."
78 def _prompt_noprint_end(attr):
79 "Ends a sequence of non-printing characters."
82 prompt_substitutions = {
92 '[': _prompt_noprint_begin,
93 ']': _prompt_noprint_end
97 """Generate help dynamically from the __doc__ strings of attribute
101 keys = prompt_substitutions.keys()
104 result += ' \\%s\t%s\n' % (key, prompt_substitutions[key].__doc__)
106 A substitution can be used in a simple form, like "\\f".
107 An argument can also be passed to it, like "\\f{name}".
108 The meaning of the argument depends on the particular substitution."""
111 def substitute_prompt(prompt):
112 "Perform substitutions on PROMPT."
118 if prompt[i] == '\\':
124 if cmdch in prompt_substitutions:
125 cmd = prompt_substitutions[cmdch]
127 if i + 1 < plen and prompt[i + 1] == '{':
129 while j < plen and prompt[j] != '}':
131 # Just ignore formatting errors.
132 if j >= plen or prompt[j] != '}':
135 arg = prompt[i + 2 : j]
139 result += str(cmd(arg))
141 # Unrecognized escapes are turned into the escaped