1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import os 6 7import cr 8 9 10class GdbDebugger(cr.Debugger): 11 """An implementation of cr.Debugger that launches gdb.""" 12 13 DETECTED = cr.Config('DETECTED') 14 15 @property 16 def enabled(self): 17 return (cr.LinuxPlatform.GetInstance().is_active and 18 self.DETECTED.Find('CR_GDB')) 19 20 def Invoke(self, targets, arguments): 21 for target in targets: 22 with target: 23 cr.Host.Execute( 24 '{CR_GDB}', '--eval-command=run', '--args', 25 '{CR_BINARY}', 26 '{CR_RUN_ARGUMENTS}', 27 *arguments 28 ) 29 30 def Attach(self, targets, arguments): 31 raise NotImplementedError('Attach not currently supported for gdb.') 32 33 @classmethod 34 def ClassInit(cls): 35 # Attempt to find a valid gdb on the path. 36 gdb_binaries = cr.Host.SearchPath('gdb') 37 if gdb_binaries: 38 cls.DETECTED.Set(CR_GDB=gdb_binaries[0]) 39 40