This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] 获取源代码行地址

Guru**** 1860730 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/1315622/get-source-code-line-address

您好!  

我想知道能否获得源代码中特定行的地址。

我将尝试确保在目标命中断点时将其停止。

提前感谢。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我想知道能否在源代码中获得特定行的地址。

    您可以获取汇编代码中特定行的地址、但不能获取源代码、因为源代码是中间步骤。 例外可能是函数调用和定义。

    转至 Window -> Show View -> Disassembly。

    然后、调试器 在 反汇编中的适当位置将使其成为程序的源代码插入。 例如:

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Kier:

    感谢您的答复、  

    我需要通过 com 对象实现这一点,我正在尝试实现这个方案:  

    1. 按行号添加断点
    2. 运行
    3. 检查调试器是否命中断点(通过检查它是否被暂停)
    4. 检查调试器停止地址是否与 BP 线路地址相同

    我曾尝试通过地址和符号添加断点来实现这种方案、但效果很好。

    我的问题是、我无法获取线路地址。

    感谢你的帮助。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我会 改用断点属性。 请注意、用户指南的示例中有一些拼写错误。 缺少"Type"节点。

    下面是一个工作示例:

    // Import the DSS packages into our namespace to save on typing
    importPackage(Packages.com.ti.debug.engine.scripting)
    importPackage(Packages.com.ti.ccstudio.scripting.environment)
    importPackage(Packages.java.lang)
    
    // Create our scripting environment object - which is the main entry point into any script and
    // the factory for creating other Scriptable ervers and Sessions
    var script = ScriptingEnvironment.instance()
    
    // Create a log file in the current directory to log script execution
    script.traceBegin("BreakpointsTestLog.xml", "DefaultStylesheet.xsl")
    
    // Set our TimeOut
    script.setScriptTimeout(15000)
    
    // Log everything
    script.traceSetConsoleLevel(TraceLevel.INFO)
    script.traceSetFileLevel(TraceLevel.ALL)
    
    // Get the Debug Server and start a Debug Session
    debugServer = script.getServer("DebugServer.1")
    debugServer.setConfig("./targetConfigs/MSPM0G3507.ccxml");
    debugSession = debugServer.openSession("*", "CORTEX_M0P")
    
    debugSession.target.connect();
    
    // Load a program
    // (ScriptingEnvironment has a concept of a working folder and for all of the APIs which take
    // path names as arguments you can either pass a relative path or an absolute path)
    debugSession.memory.loadProgram("./Debug/gpio_toggle_output_LP_MSPM0G3507_nortos_ticlang.out")
    
    // for setting breakpoint to perform profile control point
    var bpProps2 = debugSession.breakpoint.createProperties(1);
    
    bpProps2.setSourceLocation("Hardware Configuration.Type.Location", "C:/Users/user/workspace_v1250/gpio_toggle_output_LP_MSPM0G3507_nortos_ticlang/gpio_toggle_output.c", 51);
    
    var bp2 = debugSession.breakpoint.add(bpProps2); // add breakpoint
    
    var bpLoc = bpProps2.getNumeric("Hardware Configuration.Type.Location");    // get address of breakpoint
    
    script.traceWrite("BP Location: 0x" + bpLoc.toString(16));
    
    if(debugSession.expression.evaluate("PC") != bpLoc)
    {
        script.traceWrite("PC: 0x" + debugSession.expression.evaluate("PC").toString(16));
        debugSession.target.run();
    }
    
    script.traceWrite("PC: 0x" + debugSession.expression.evaluate("PC").toString(16));
    script.traceWrite("Halted at breakpoint");
    
    // All done
    debugSession.target.disconnect();
    debugSession.terminate()
    debugServer.stop()
    
    script.traceSetConsoleLevel(TraceLevel.INFO)
    script.traceWrite("TEST SUCCEEDED!")
    
    // Stop logging and exit.
    script.traceEnd()

    控制台输出:

    谢谢

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Ki 您好

    谢谢 你,这帮了我很多。

    我还有一个关于这个参数的问题  "Hardware Configuration.Type.Location",  此参数是否为常量参数?

    谢谢

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我还有一个关于此参数的问题  "Hardware Configuration.Type.Location",  此参数是否是常量参数?

    不可以、您可以更改该值。 如果您使用数字值设置该值、它将在地址上设置它。 在我的示例中、我传入了一个包含源文件和行的字符串。

    读回该值时、如果我读取一个字符串、我会得到源信息和行信息。 在我的示例中、我读取了一个数字值、因此我得到了地址。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    好的,非常感谢你的帮助