Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: mojo/devtools/common/android_gdb/session.py

Issue 1325593004: Allow mojo_debug gdb attach to search symbols in multiple directories. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/devtools/common/mojo_debug » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """ 5 """
6 Manages a debugging session with GDB. 6 Manages a debugging session with GDB.
7 7
8 This module is meant to be imported from inside GDB. Once loaded, the 8 This module is meant to be imported from inside GDB. Once loaded, the
9 |DebugSession| attaches GDB to a running Mojo Shell process on an Android 9 |DebugSession| attaches GDB to a running Mojo Shell process on an Android
10 device using a remote gdbserver. 10 device using a remote gdbserver.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 _gdb_execute("info proc map").split('\n')] 64 _gdb_execute("info proc map").split('\n')]
65 if len(x) == 5 and x[4][0] == '/'] 65 if len(x) == 5 and x[4][0] == '/']
66 res = {} 66 res = {}
67 for m in mappings: 67 for m in mappings:
68 libname = m.filename[m.filename.rfind('/') + 1:] 68 libname = m.filename[m.filename.rfind('/') + 1:]
69 res[libname] = res.get(libname, []) + [m] 69 res[libname] = res.get(libname, []) + [m]
70 return res.values() 70 return res.values()
71 71
72 72
73 class DebugSession(object): 73 class DebugSession(object):
74 def __init__(self, build_directory, package_name, pyelftools_dir, adb): 74 def __init__(self, build_directory_list, package_name, pyelftools_dir, adb):
75 self._build_directory = build_directory 75 build_directories = build_directory_list.split(',')
76 if not os.path.exists(self._build_directory): 76 if len(build_directories) == 0 or not all(map(os.path.exists,
77 logging.fatal("Please pass a valid build directory") 77 build_directories)):
78 logging.fatal("Please pass a list of valid build directories")
78 sys.exit(1) 79 sys.exit(1)
79 self._package_name = package_name 80 self._package_name = package_name
80 self._adb = adb 81 self._adb = adb
81 self._remote_file_cache = os.path.join(os.getenv('HOME'), '.mojosymbols') 82 self._remote_file_cache = os.path.join(os.getenv('HOME'), '.mojosymbols')
82 83
83 if pyelftools_dir != None: 84 if pyelftools_dir != None:
84 sys.path.append(pyelftools_dir) 85 sys.path.append(pyelftools_dir)
85 try: 86 try:
86 import elftools.elf.elffile as elffile 87 import elftools.elf.elffile as elffile
87 except ImportError: 88 except ImportError:
88 logging.fatal("Unable to find elftools module; please install pyelftools " 89 logging.fatal("Unable to find elftools module; please install pyelftools "
89 "and specify its path on the command line using " 90 "and specify its path on the command line using "
90 "--pyelftools-dir.") 91 "--pyelftools-dir.")
91 sys.exit(1) 92 sys.exit(1)
92 93
93 self._elffile_module = elffile 94 self._elffile_module = elffile
94 95
95 self._libraries = self._find_libraries(build_directory) 96 self._libraries = self._find_libraries(build_directories)
96 self._rfc = RemoteFileConnection('localhost', 10000) 97 self._rfc = RemoteFileConnection('localhost', 10000)
97 self._remote_file_reader_process = None 98 self._remote_file_reader_process = None
98 if not os.path.exists(self._remote_file_cache): 99 if not os.path.exists(self._remote_file_cache):
99 os.makedirs(self._remote_file_cache) 100 os.makedirs(self._remote_file_cache)
100 self._done_mapping = set() 101 self._done_mapping = set()
101 self._downloaded_files = [] 102 self._downloaded_files = []
102 103
103 def __del__(self): 104 def __del__(self):
104 # Note that, per python interpreter documentation, __del__ is not 105 # Note that, per python interpreter documentation, __del__ is not
105 # guaranteed to be called when the interpreter (GDB, in our case) quits. 106 # guaranteed to be called when the interpreter (GDB, in our case) quits.
106 # Also, most (all?) globals are no longer available at this time (launching 107 # Also, most (all?) globals are no longer available at this time (launching
107 # a subprocess does not work). 108 # a subprocess does not work).
108 self.stop() 109 self.stop()
109 110
110 def stop(self, _unused_return_value=None): 111 def stop(self, _unused_return_value=None):
111 if self._remote_file_reader_process != None: 112 if self._remote_file_reader_process != None:
112 self._remote_file_reader_process.kill() 113 self._remote_file_reader_process.kill()
113 114
114 def _find_libraries(self, lib_dir): 115 def _find_libraries(self, lib_dirs):
115 """Finds all libraries in |lib_dir| and key them by their signatures. 116 """Finds all libraries in |lib_dirs| and key them by their signatures.
116 """ 117 """
117 res = {} 118 res = {}
118 for fn in glob.glob('%s/*.so' % lib_dir): 119 for lib_dir in lib_dirs:
119 with open(fn, 'r') as f: 120 for fn in glob.glob('%s/*.so' % lib_dir):
120 s = get_signature(f, self._elffile_module) 121 with open(fn, 'r') as f:
121 if s is not None: 122 s = get_signature(f, self._elffile_module)
122 res[s] = fn 123 if s is not None:
124 res[s] = fn
123 return res 125 return res
124 126
125 def _associate_symbols(self, mapping, local_file): 127 def _associate_symbols(self, mapping, local_file):
126 with open(local_file, "r") as f: 128 with open(local_file, "r") as f:
127 elf = self._elffile_module.ELFFile(f) 129 elf = self._elffile_module.ELFFile(f)
128 s = elf.get_section_by_name(".text") 130 s = elf.get_section_by_name(".text")
129 text_address = mapping[0].start + s['sh_offset'] 131 text_address = mapping[0].start + s['sh_offset']
130 _gdb_execute("add-symbol-file %s 0x%x" % (local_file, text_address)) 132 _gdb_execute("add-symbol-file %s 0x%x" % (local_file, text_address))
131 133
132 def _download_file(self, signature, remote): 134 def _download_file(self, signature, remote):
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 310
309 def complete(self, text, _unused_word): 311 def complete(self, text, _unused_word):
310 if text == self._UPDATE_COMMAND: 312 if text == self._UPDATE_COMMAND:
311 return ('all', 'current') 313 return ('all', 'current')
312 elif text in self._UPDATE_COMMAND + ' all': 314 elif text in self._UPDATE_COMMAND + ' all':
313 return ['all'] 315 return ['all']
314 elif text in self._UPDATE_COMMAND + ' current': 316 elif text in self._UPDATE_COMMAND + ' current':
315 return ['current'] 317 return ['current']
316 else: 318 else:
317 return [] 319 return []
OLDNEW
« no previous file with comments | « no previous file | mojo/devtools/common/mojo_debug » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698