- Changed backtrace view to a treeview
[pygdb.git] / GdbTerminal.py
index f8a8614e1f3c7dd1040f616d52987233894fe74d..842f76862123027b809e690aebab5fda54ae220b 100644 (file)
@@ -154,7 +154,53 @@ class GdbTerminal (DbgTerminal.DbgTerminal):
                return self.__getAnswerFromCmd("list\n")
 
        def getBacktrace(self):
-               return self.__getAnswerFromCmd("bt\n")
+
+               stack = []
+               answ = self.__getAnswerFromCmd("bt\n")
+
+               rxstartfull = re.compile("^\#\d+\s+0x[0-9a-f]+\s+in\s+\S+\s+\(")
+               rxstartshort = re.compile("^\#\d+\s+\S+\s+\(")
+               rxpos = re.compile("at \S+:\d+$")
+
+               try:
+
+                       i=0
+                       while i<len(answ):
+                               line = answ[i]
+
+                               while not rxstartfull.search(line) and not rxstartshort.search(line):
+                                       print "Warning: '", line, "' does not match bt entry."
+                                       i+=1
+                                       line = answ[i]
+
+                               parts = line.split()
+
+                               if rxstartfull.search(line):
+                                       func = parts[3]
+                                       addr = parts[1]
+                               else:
+                                       func = parts[1]
+                                       addr = None
+
+
+                               #Search for file position
+                               while not rxpos.search(line):
+                                       print "Warning: '", line, "' does not match file pos marker."
+                                       i+=1
+                                       line = answ[i]
+
+                               parts = line.split()
+                               pos = parts[-1]
+                               [file,lineno] = pos.split(":")
+
+                               stack += [[addr,func,file,lineno]]
+
+                               i+=1
+
+               except IndexError:
+                       pass
+
+               return stack
 
        def waitForPrompt(self, his):
                rx = "^\(gdb\)"