@@ -451,7 +451,7 @@ def run_pb(self, command, async=False, gdb=False):
451451 if self .verbose :
452452 print (self .cmd )
453453 if gdb :
454- return GDBobj ([self .probackup_path ] + command , verbose = True )
454+ return GDBobj ([self .probackup_path ] + command , self . verbose )
455455 if async :
456456 return subprocess .Popen (
457457 self .cmd ,
@@ -913,13 +913,30 @@ def __str__(self):
913913
914914class GDBobj (ProbackupTest ):
915915 def __init__ (self , cmd , verbose ):
916+ self .verbose = verbose
917+
918+ # Check gdb presense
919+ try :
920+ gdb_version , _ = subprocess .Popen (
921+ ["gdb" , "--version" ],
922+ stdout = subprocess .PIPE
923+ ).communicate ()
924+ except OSError :
925+ raise GdbException ("Couldn't find gdb on the path" )
926+
916927 self .base_cmd = [
917- '/usr/bin/ gdb' ,
928+ 'gdb' ,
918929 '--interpreter' ,
919930 'mi2' ,
920931 '--args'
921932 ] + cmd
922- self .verbose = verbose
933+
934+ # Get version
935+ gdb_version_number = re .search (
936+ b"^GNU gdb [^\d]*(\d+)\.(\d)" ,
937+ gdb_version )
938+ self .major_version = int (gdb_version_number .group (1 ))
939+ self .minor_version = int (gdb_version_number .group (2 ))
923940 if self .verbose :
924941 print ([' ' .join (map (str , self .base_cmd ))])
925942
@@ -929,10 +946,11 @@ def __init__(self, cmd, verbose):
929946 stdout = subprocess .PIPE ,
930947 stderr = subprocess .STDOUT ,
931948 bufsize = 0 , universal_newlines = True
932- )
949+ )
933950 self .gdb_pid = self .proc .pid
934951
935- # discard stuff
952+ # discard data from pipe,
953+ # is there a way to do it a less derpy way?
936954 while True :
937955 line = self .proc .stdout .readline ()
938956 if not line .startswith ('(gdb)' ):
@@ -943,52 +961,49 @@ def __init__(self, cmd, verbose):
943961 def set_breakpoint (self , location ):
944962 result = self ._execute ('break ' + location )
945963 success = False
946- for line in result .splitlines ():
947- # Success
964+ for line in result :
948965 if line .startswith ('~"Breakpoint' ):
949966 success = True
950967 break
951968 if line .startswith ('^error' ) or line .startswith ('(gdb)' ):
952969 break
953- # discard initial data from pipe,
954- # is there a way to do it a less derpy way?
955- if line .startswith ('&' ):
956- if line .startswith ('&"break' ):
957- pass
958- if line .startswith ('&"Function' ):
959- GdbBreakpointException = GdbException ()
960- raise GdbBreakpointException (line )
961- if line .startswith ('&"No line' ):
962- GdbBreakpointException = GdbException ()
963- raise GdbBreakpointException (line )
970+
971+ if line .startswith ('&"break' ):
972+ pass
973+
974+ if line .startswith ('&"Function' ):
975+ raise GdbException (line )
976+
977+ if line .startswith ('&"No line' ):
978+ raise GdbException (line )
964979 return success
965980
966981 def run (self ):
967982 result = self ._execute ('run' )
968- for line in result . splitlines () :
983+ for line in result :
969984 if line .startswith ('*stopped,reason="breakpoint-hit"' ):
970985 return 'breakpoint-hit'
971986 if line .startswith ('*stopped,reason="exited-normally"' ):
972987 return 'exit correct'
973988
974989 def continue_execution (self , sync = True ):
975990 result = self ._execute ('continue' )
976- for line in result . splitlines () :
991+ for line in result :
977992 if line .startswith ('*stopped,reason="breakpoint-hit"' ):
978993 return 'breakpoint-hit'
979994 if line .startswith ('*stopped,reason="exited-normally"' ):
980995 return 'exit correct'
981996
982997 # use for breakpoint, run, continue
983998 def _execute (self , cmd ):
984- output = ''
999+ output = []
9851000 self .proc .stdin .flush ()
9861001 self .proc .stdin .write (cmd + '\n ' )
9871002 self .proc .stdin .flush ()
9881003
9891004 while True :
9901005 line = self .proc .stdout .readline ()
991- output = output + line
1006+ output += [ line ]
9921007 if self .verbose :
9931008 print (line )
9941009 if line == '^done\n ' or line .startswith ('*stopped' ):
0 commit comments