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

时间:2022-01-28 12:59:18

I am trying to build a script that sets breakpoints in winIDEA (this ide will run a project, that has different comments). The breakpoints must be set in winIDEA after a specific comment is recognised. I am somewhat new to this language and I am having problems making this script. I am not sure if what I have here is good, but I am trying to get the line where the comment is recognised, and then set a breakpoint in the program at this specific line.

我正在尝试构建一个在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')

I get instead a random line, and the position where I encounter my element in the string (I make the script that runs in ide a string at some point). I have no idea left... Help a newbie!

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

1 个解决方案

#1


0  

This is what worked up for me:

这对我有用:

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)

#1


0  

This is what worked up for me:

这对我有用:

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)