summary history branches tags files
commit:d9d48b38362f9cc4ec25e285adda144f2dff3273
author:mrmekon
committer:mrmekon
date:Fri Nov 9 20:02:42 2012 -0500
parents:12823c37172e3c539f90c2aad5998a34595a08e7
Breakpoints can be specified in multiple ways.  Address, file/line, function, or just line.
diff --git a/README.md b/README.md
line changes: +0/-1
index b2eeea4..9b54e8e
--- a/README.md
+++ b/README.md
@@ -41,7 +41,6 @@ I wrote this because mdb.sh is currently incomplete, and nearly unusable, so loa
 
 Basic functionality:
 * Display source code
-* Set breakpoints by file/line
 * View memory
 * View disassembly
 * View global and local symbols

diff --git a/mdb/picdebugger.py b/mdb/picdebugger.py
line changes: +8/-1
index 3b09075..bfae982
--- a/mdb/picdebugger.py
+++ b/mdb/picdebugger.py
@@ -183,7 +183,6 @@ class picdebugger(com.microchip.mplab.util.observers.Observer):
                     break
             except TranslatorException:
                 continue
-        print "%s:%d ==> 0x%X" % (fullpath.split("/")[-1], line+i, info.lStartAddr)
         addr = info.lStartAddr
         return addr
 
@@ -220,6 +219,14 @@ class picdebugger(com.microchip.mplab.util.observers.Observer):
             return data        
         return None
 
+    def getFunctionAddress(self, funcname):
+        sv = self.assembly.getLookup().lookup(SymbolViewProvider)
+        info = sv.getRawSymbol(funcname)
+        if not info or info.Type() != 64: # 64 is magic number found by inspection
+            return None
+        return info.Address()
+    
+
     def getSymbolValue(self, symbol):
         sv = self.assembly.getLookup().lookup(SymbolViewProvider)
         info = sv.getRawSymbol(symbol)

diff --git a/picdb.py b/picdb.py
line changes: +39/-3
index 01872c1..c8fef46
--- a/picdb.py
+++ b/picdb.py
@@ -75,15 +75,51 @@ Usage: load <file>
         self.dbg.load(args)
         self.dbg.reset()
 
+    def _addrFileAndLine(self, file, line):
+        '''Return address for instruction at given line of given file.'''
+        return self.dbg.findBreakableAddressInFile(file, line)
+        
+    def _addrFunction(self, fn):
+        '''Return address of function fn (string)'''
+        return self.dbg.getFunctionAddress(fn)
+
+    def _addrLine(self, line):
+        '''Return address of instruction at given line in current file'''
+        pc = self.dbg.getPC()
+        (curfile,_) = self.dbg.addressToSourceLine(pc, stripdir=False)
+        return self.dbg.findBreakableAddressInFile(curfile, line)
+
+    def _safeStrToInt(self, numstr):
+        '''Try to convert string to int, return None on failure'''
+        try:
+            return int(numstr,0)
+        except ValueError:
+            return None
+
     def cmdBreak(self, args):
         '''
 Set a breakpoint
-Usage: break <address>
+Usage:
+    break *<address>
+    break <file>:<line>
+    break <line>
+    break <function name>
 <address> is a memory address specified in decimal, or hexadecimal with an '0x'
 prefix.
 '''
-        addr = int(args,0)
-        self.dbg.setBreakpoint(addr)
+        elems = args.split(":")
+        if args[0] == "*": # *<address>
+            addr = self._safeStrToInt(args[1:])
+        elif len(elems) >= 2:
+            addr = self._addrFileAndLine(elems[0], self._safeStrToInt(elems[1]))
+        else:
+            num = self._safeStrToInt(elems[0])
+            if num:
+                addr = self._addrLine(num)
+            else:
+                addr = self._addrFunction(elems[0])
+        return self.dbg.setBreakpoint(addr)
+
 
     def cmdBreakpoints(self, args):
         '''