Python脚本设置断点和注释的相遇

时间:2014-04-05 10:44:02

标签: python scripting ide breakpoints

我正在尝试构建一个在winIDEA中设置断点的脚本(此ide将运行一个具有不同注释的项目)。在识别出特定注释后,必须在winIDEA中设置断点。我对这种语言有点新,我在编写这个脚本时遇到了问题。我不确定我在这里的内容是否良好,但我正在尝试识别注释的行,然后在该特定行的程序中设置断点。

import inspect
import logging

import isystem.connect as ic
import sys

connMgr = ic.ConnectionMgr()
connMgr.connectMRU('')

dbg = ic.CDebugFacade(connMgr)
bc = ic.CBreakpointController(connMgr)
exe = ic.CExecutionController(connMgr)

logging.basicConfig(
    format = "%(levelname) -10s %(asctime)s %(message)s",
    level = logging.DEBUG

def test():

    caller_list = []
    frame = inspect.currentframe()

    this_frame = frame  # Save current frame.

    while frame.f_back:
        print frame
        caller_list.append('{0}()'.format(frame.f_code.co_name))
        frame = frame.f_back

    caller_line = this_frame.f_back.f_lineno
    callers =  '/'.join(reversed(caller_list))

    logging.info('Line {0} : {1}'.format(caller_line, callers))
    print caller_line

def foo():
   test()

def bar():
   foo()

test()

datafile= file(r'C:\Documents and Settings\stiral1\Desktop\function.py')
stringfile=datafile.read()
item_search="haha"
counter=0

print stringfile.find(item_search,counter)


while counter != -1:
    print stringfile.find(item_search,counter)
    bc.setBP(counter,r'C:\_DevTools\winIDEA\2012\Examples\Simulator\PPC\Simple\main.c')

我得到的是一个随机行,以及我在字符串中遇到我的元素的位置(我在某个时候创建​​了一个在一个字符串中运行的脚本)。我不知道离开......帮助一个新手!

1 个答案:

答案 0 :(得分:0)

这对我有用:

def wdSetBPComment(wdPrmStr):
    assert(wdGetNrOfSubStrings(wdPrmStr) == 2)
    comment = wdGetSubString_1(wdPrmStr)
    function = wdGetSubString_2(wdPrmStr)

    gl_tpLocation.setResourceName(function)
    gl_tpLocation.setSearch(ic.E_TRUE)
    gl_tpLocation.setMatchingType(ic.CTestLocation.E_MATCH_PLAIN)
    gl_tpLocation.setSearchPattern(comment)
    lineLocation = addrCtrl.getSourceLocation(gl_tpLocation)
    wdSetBreakpoint(lineLocation.getFileName()+lineLocation.getLineNumber())
    gl_bcCtrl.setBP(lineNo,fileName)

    return (gl_wdOkStr)