Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(25)

Side by Side Diff: Tools/gdb/libpython.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Python/_warnings.c ('k') | Tools/msi/msi.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 ''' 2 '''
3 From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb 3 From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb
4 to be extended with Python code e.g. for library-specific data visualizations, 4 to be extended with Python code e.g. for library-specific data visualizations,
5 such as for the C++ STL types. Documentation on this API can be seen at: 5 such as for the C++ STL types. Documentation on this API can be seen at:
6 http://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html 6 http://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html
7 7
8 8
9 This python module deals with the case when the process being debugged (the 9 This python module deals with the case when the process being debugged (the
10 "inferior process" in gdb parlance) is itself python, or more specifically, 10 "inferior process" in gdb parlance) is itself python, or more specifically,
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 return self.co.addr2line(self.f_lasti) 898 return self.co.addr2line(self.f_lasti)
899 #except ValueError: 899 #except ValueError:
900 # return self.f_lineno 900 # return self.f_lineno
901 901
902 def current_line(self): 902 def current_line(self):
903 '''Get the text of the current source line as a string, with a trailing 903 '''Get the text of the current source line as a string, with a trailing
904 newline character''' 904 newline character'''
905 if self.is_optimized_out(): 905 if self.is_optimized_out():
906 return '(frame information optimized out)' 906 return '(frame information optimized out)'
907 filename = self.filename() 907 filename = self.filename()
908 try: 908 with open(os_fsencode(filename), 'r') as f:
909 f = open(os_fsencode(filename), 'r')
910 except IOError:
911 return None
912 with f:
913 all_lines = f.readlines() 909 all_lines = f.readlines()
914 # Convert from 1-based current_line_num to 0-based list offset: 910 # Convert from 1-based current_line_num to 0-based list offset:
915 return all_lines[self.current_line_num()-1] 911 return all_lines[self.current_line_num()-1]
916 912
917 def write_repr(self, out, visited): 913 def write_repr(self, out, visited):
918 if self.is_optimized_out(): 914 if self.is_optimized_out():
919 out.write('(frame information optimized out)') 915 out.write('(frame information optimized out)')
920 return 916 return
921 out.write('Frame 0x%x, for file %s, line %i, in %s (' 917 out.write('Frame 0x%x, for file %s, line %i, in %s ('
922 % (self.as_address(), 918 % (self.as_address(),
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 1423
1428 # Not found: 1424 # Not found:
1429 return None 1425 return None
1430 1426
1431 def print_summary(self): 1427 def print_summary(self):
1432 if self.is_evalframeex(): 1428 if self.is_evalframeex():
1433 pyop = self.get_pyop() 1429 pyop = self.get_pyop()
1434 if pyop: 1430 if pyop:
1435 line = pyop.get_truncated_repr(MAX_OUTPUT_LEN) 1431 line = pyop.get_truncated_repr(MAX_OUTPUT_LEN)
1436 write_unicode(sys.stdout, '#%i %s\n' % (self.get_index(), line)) 1432 write_unicode(sys.stdout, '#%i %s\n' % (self.get_index(), line))
1437 line = pyop.current_line() 1433 sys.stdout.write(pyop.current_line())
1438 if line is not None:
1439 sys.stdout.write(line)
1440 else: 1434 else:
1441 sys.stdout.write('#%i (unable to read python frame information)\ n' % self.get_index()) 1435 sys.stdout.write('#%i (unable to read python frame information)\ n' % self.get_index())
1442 else: 1436 else:
1443 sys.stdout.write('#%i\n' % self.get_index()) 1437 sys.stdout.write('#%i\n' % self.get_index())
1444 1438
1445 def print_traceback(self): 1439 def print_traceback(self):
1446 if self.is_evalframeex(): 1440 if self.is_evalframeex():
1447 pyop = self.get_pyop() 1441 pyop = self.get_pyop()
1448 if pyop: 1442 if pyop:
1449 pyop.print_traceback() 1443 pyop.print_traceback()
1450 line = pyop.current_line() 1444 sys.stdout.write(' %s\n' % pyop.current_line().strip())
1451 if line is not None:
1452 sys.stdout.write(' %s\n' % line.strip())
1453 else: 1445 else:
1454 sys.stdout.write(' (unable to read python frame information)\n' ) 1446 sys.stdout.write(' (unable to read python frame information)\n' )
1455 else: 1447 else:
1456 sys.stdout.write(' (not a python frame)\n') 1448 sys.stdout.write(' (not a python frame)\n')
1457 1449
1458 class PyList(gdb.Command): 1450 class PyList(gdb.Command):
1459 '''List the current Python source code, if any 1451 '''List the current Python source code, if any
1460 1452
1461 Use 1453 Use
1462 py-list START 1454 py-list START
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 filename = pyop.filename() 1494 filename = pyop.filename()
1503 lineno = pyop.current_line_num() 1495 lineno = pyop.current_line_num()
1504 1496
1505 if start is None: 1497 if start is None:
1506 start = lineno - 5 1498 start = lineno - 5
1507 end = lineno + 5 1499 end = lineno + 5
1508 1500
1509 if start<1: 1501 if start<1:
1510 start = 1 1502 start = 1
1511 1503
1512 try: 1504 with open(os_fsencode(filename), 'r') as f:
1513 f = open(os_fsencode(filename), 'r')
1514 except IOError as err:
1515 sys.stdout.write('Unable to open %s: %s\n'
1516 % (filename, err))
1517 return
1518 with f:
1519 all_lines = f.readlines() 1505 all_lines = f.readlines()
1520 # start and end are 1-based, all_lines is 0-based; 1506 # start and end are 1-based, all_lines is 0-based;
1521 # so [start-1:end] as a python slice gives us [start, end] as a 1507 # so [start-1:end] as a python slice gives us [start, end] as a
1522 # closed interval 1508 # closed interval
1523 for i, line in enumerate(all_lines[start-1:end]): 1509 for i, line in enumerate(all_lines[start-1:end]):
1524 linestr = str(i+start) 1510 linestr = str(i+start)
1525 # Highlight current line: 1511 # Highlight current line:
1526 if i + start == lineno: 1512 if i + start == lineno:
1527 linestr = '>' + linestr 1513 linestr = '>' + linestr
1528 sys.stdout.write('%4s %s' % (linestr, line)) 1514 sys.stdout.write('%4s %s' % (linestr, line))
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 if not pyop_frame: 1663 if not pyop_frame:
1678 print 'Unable to read information on python frame' 1664 print 'Unable to read information on python frame'
1679 return 1665 return
1680 1666
1681 for pyop_name, pyop_value in pyop_frame.iter_locals(): 1667 for pyop_name, pyop_value in pyop_frame.iter_locals():
1682 print ('%s = %s' 1668 print ('%s = %s'
1683 % (pyop_name.proxyval(set()), 1669 % (pyop_name.proxyval(set()),
1684 pyop_value.get_truncated_repr(MAX_OUTPUT_LEN))) 1670 pyop_value.get_truncated_repr(MAX_OUTPUT_LEN)))
1685 1671
1686 PyLocals() 1672 PyLocals()
OLDNEW
« no previous file with comments | « Python/_warnings.c ('k') | Tools/msi/msi.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+