MCPcopy Index your code
hub / github.com/python/cpython / invoke

Method invoke

Tools/gdb/libpython.py:1946–2001  ·  view source on GitHub ↗
(self, args, from_tty)

Source from the content-addressed store, hash-verified

1944
1945
1946 def invoke(self, args, from_tty):
1947 import re
1948
1949 start = None
1950 end = None
1951
1952 m = re.match(r'\s*(\d+)\s*', args)
1953 if m:
1954 start = int(m.group(0))
1955 end = start + 10
1956
1957 m = re.match(r'\s*(\d+)\s*,\s*(\d+)\s*', args)
1958 if m:
1959 start, end = map(int, m.groups())
1960
1961 # py-list requires an actual PyEval_EvalFrameEx frame:
1962 frame = Frame.get_selected_bytecode_frame()
1963 if not frame:
1964 print('Unable to locate gdb frame for python bytecode interpreter')
1965 return
1966
1967 pyop = frame.get_pyop()
1968 if not pyop or pyop.is_optimized_out():
1969 print(UNABLE_READ_INFO_PYTHON_FRAME)
1970 return
1971
1972 filename = pyop.filename()
1973 lineno = pyop.current_line_num()
1974 if lineno is None:
1975 print('Unable to read python frame line number')
1976 return
1977
1978 if start is None:
1979 start = lineno - 5
1980 end = lineno + 5
1981
1982 if start<1:
1983 start = 1
1984
1985 try:
1986 f = open(os.fsencode(filename), 'r', encoding="utf-8")
1987 except IOError as err:
1988 sys.stdout.write('Unable to open %s: %s\n'
1989 % (filename, err))
1990 return
1991 with f:
1992 all_lines = f.readlines()
1993 # start and end are 1-based, all_lines is 0-based;
1994 # so [start-1:end] as a python slice gives us [start, end] as a
1995 # closed interval
1996 for i, line in enumerate(all_lines[start-1:end]):
1997 linestr = str(i+start)
1998 # Highlight current line:
1999 if i + start == lineno:
2000 linestr = '>' + linestr
2001 sys.stdout.write('%4s %s' % (linestr, line))
2002
2003

Callers

nothing calls this directly

Calls 13

enumerateFunction · 0.85
strFunction · 0.85
get_pyopMethod · 0.80
openFunction · 0.50
matchMethod · 0.45
groupMethod · 0.45
groupsMethod · 0.45
is_optimized_outMethod · 0.45
filenameMethod · 0.45
current_line_numMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected